【发布时间】:2011-06-10 17:20:37
【问题描述】:
我的 RootViewController 是一个 UITableViewController。以编程方式添加 UINavigationController:
_navigationController = [[[UINavigationController alloc] initWithRootViewController:_rootViewController] autorelease];
[self.window addSubview:_navigationController.view];
[self.window makeKeyAndVisible];
在rootviewController中,在选择行时应加载DetailViewController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Switch to detail");
CCouchDBDocument *selectedObject = [self.contentsList objectAtIndex:indexPath.row];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
[self.view addSubview:detailViewController.view];
[detailViewController setDetailItem: selectedObject];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
如果没有 addSubView,屏幕上什么也不会发生。我之前看到的所有示例都只使用 pushViewController。而且,加载 DetailView 大约需要 4 秒。这太长了(它目前是空的,只有一个标签)。当我尝试设置 navigationTitle (self.title = @"Hello";) 时,RootViewController 中的标题保持不变,因此 navigationController 一定有问题。
我尝试将所有内容都放入 AppDelegate 并使用 switchView 方法。问题是 setDetailItem 的调用,如果我使用 switch 方法,我无法调用它。
将 DetailView 从 RootViewController 加载到导航堆栈以及以后可能从 DetailViewController 加载更多内容的正确方法是什么?
更新 我又从一个基于 Window 的应用程序开始。添加了一个 UITableViewController 作为“RootViewController”,并在 AppDelegate 中使用 UINavigationController 对其进行了初始化(在 XIB 中完全没有做任何事情)。当我尝试设置 self.navigationController.title = @"Test";在 ViewDidLoad 中,没有任何反应。
怎么了?
【问题讨论】:
标签: objective-c ios4 uinavigationcontroller xcode4