这是我的第一篇文章,所以请温柔。
我在 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/