如何从rootViewController中的多级导航更新detailViewController.detailItem

Pee*_*etz 2 xcode ipad uisplitviewcontroller

这是我的第一篇文章,所以请轻轻一点.

我在xcode中使用基于Split View的基本应用程序,但已对其进行了编辑,以便rootViewController不会简单地更新detailViewController,而是将新的UITableViewController(taskViewController)推送到导航堆栈.

我的问题是,当我从taskViewController调用以下内容时没有任何反应:

detailViewController.detailItem = [NSString stringWithFormat:@"Row %d", indexPath.row];
Run Code Online (Sandbox Code Playgroud)

如果我从rootViewController调用它,而不是将新的UITableView推送到堆栈,它可以工作.

当选择一个单元格时,这是我的rootViewController代码:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TaskViewController *taskViewController = [[TaskViewController alloc] init];

    taskViewController.title = [NSString stringWithFormat:@"Unit %d",indexPath.row];

    [self.navigationController pushViewController:taskViewController animated:YES];

    [taskViewController release];
}
Run Code Online (Sandbox Code Playgroud)

我在这里做错了吗?我在UISplitViewController的rootViewController中正确使用导航控制器吗?

Luk*_*ice 5

你的rootViewController可以访问detailViewController,因为它有一个referance.如果你将一个新控制器推到导航堆栈上,那么它不会自动了解DetailViewController.

NSLog倒是detailViewController你taskVC,看它是否有一个指针?

您通常会在创建时将其设置为:

 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        TaskViewController *taskViewController = [[TaskViewController alloc] init];

        taskViewController.title = [NSString stringWithFormat:@"Unit %d",indexPath.row];

        taskViewController.detailViewController = self.detailViewController;

        [self.navigationController pushViewController:taskViewController animated:YES];

        [taskViewController release];
    }
Run Code Online (Sandbox Code Playgroud)