0

嗨,我有一个 UITableViewController,它由 Playlist 对象填充,它们包含 Song 对象。我想要的是当用户在我的 TVC 中点击播放列表名称时触发 UIPageViewController,我将通过在 UITableViewController 中点击的播放列表初始化其模型。然后它会在另一个 ViewController 中显示我想要的东西。

UIPageViewController 实现在我的应用程序中的工作方式如下:

ModelController --> RootViewController --> DataViewController (就像苹果的例子)

到目前为止,我已经启动并运行了所有内容,但是我无法使用被点击的播放列表正确初始化模型。在我的 PlaylistsTVC 中,我有一个 prepareForSegue 方法,它定义了目标视图控制器,并且 arr 保存了被点击的播放列表的歌曲,但我不知道如何将它传递给 ModelController。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
     if (sender)
     {
         if ([segue.identifier isEqualToString:@"Segue"])
        {
            NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
            NSArray *arr = @[[[self.pdc.playlistMasterList objectAtIndex:indexPath.row] songs]];
            NSLog(@"arr: %@", arr);
            RootViewController *rvc = (RootViewController *)segue.destinationViewController;
            rvc.hidesBottomBarWhenPushed = YES;
        }
    }

}

我试图在我的 PlaylistDataController 类中设置一个数组,然后在 ModelController 类中创建一个新实例,但它不起作用。我还尝试在 NSUserDefaults 中对充满歌曲的数组进行编码和解码,然后将其传递给 ModelController,只是想看看它是否可以工作,但也没有运气。

任何人都可以从我上面描述的 segue 方法中帮助如何初始化页面视图控制器的模型吗?或者任何其他关于此事的想法都会受到欢迎。

谢谢!

4

1 回答 1

0

(I'm a bit confused by your controller naming...)

If you want to work with the array in RootViewController, then your approach was basically correct. You need a property in rvc and set it in prepareForSegue. E.g.:

...
RootViewController *rvc = (RootViewController *)segue.destinationViewController;
[rvc.theArray initWithArray:arr];
...
于 2013-01-31T21:53:58.787 回答