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

标签 xcode uisplitviewcontroller ipad

这是我的第一篇文章,所以请温柔。

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

我的问题是,当我现在从我的 taskViewController 调用以下内容时,什么也没有发生:

detailViewController.detailItem = [NSString stringWithFormat:@"Row %d", indexPath.row];

如果我从 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];
}

我在这里做错了什么吗?我是否在 UISplitViewController 的 rootViewController 中正确使用了导航 Controller ?

最佳答案

您的rootViewController可以访问detailViewController,因为它有对它的引用。如果您将新 Controller 推送到导航堆栈上,那么它不会自动了解 DetailViewController。

你在你的taskVC中是否有NSLog'd detailViewController来看看它是否有指针?

您通常会在创建它时设置它,如下所示:

 - (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];
    }

关于xcode - 如何从rootViewController中的多级导航更新detailViewController.detailItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4809475/

相关文章:

Xcode 6 在提交存档时崩溃

ios - HTML5 视频播放按钮未在 iOS iPad 上显示

ios - iPad 的 SplitView 和 iPhone 的菜单抽屉

iphone - 在 XCode 4 中的多个 Storyboard之间转换

iphone - 是否可以使用 Xcode 4.4 + Mountain Lion 来使用较旧的 iPhone/iPAD 模拟器(3.2、4.0、4.2)

ios - Xcode6 通用 Storyboard和 View 大小调整

xcode - NSURL 特殊字符编码

ios - 在 Xcode UITest 中访问 app.buttons 而无需任何可用的文本供引用。

ios - 以编程方式在 UISplitViewController 中显示主视图上的幻灯片

ios - Split View Controller :Detail view layout issue in iOS6