我正在构建一个app,其委托有一个UINavigationController(navigationController)。第一个视图是一个UITabViewController(tabView),它有一个带有UITiewController的UINavigationController和一个显示一些联系人的UITableView。
我想要做的是在点击桌面视图中的联系人时(通过最顶层的navController)推送一个带有联系人信息的新视图控制器
我在appDelegate中执行以下操作:
[self.window makeKeyAndVisible];
[self.window addSubview:[navigationController view]];
TabsView *tabsView = [[TabsView alloc] initWithNibName:nil bundle:nil];
[navigationController.view addSubview:[tabsView view]];
tabsView的第一个标签加载了ContactsView.m,它有一个带有所有联系人的UINavigationController,当有人点击一行时,它应该按这样推送新视图:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[table deselectRowAtIndexPath:indexPath animated:YES];
ContactSecondView * varContactSecondView = [[ContactSecondView alloc] initWithNibName:nil bundle:nil];
varContactSecondView.title = [[contactsArray objectAtIndex:indexPath.row] name];
[self.navigationController pushViewController:varContactSecondView animated:YES];
[varContactMapView release];
}
但连续接触时没有任何反应。
所以我有不同的文件:使用UINavigationController委托< - UITabViewController< - 带UINavigationController的UIViewController和UITableView;我想将ViewController推送到第一个导航控制器。
如何访问delegate的navigationController?我做得对吗?
编辑:如果这给出任何线索,当我在ContactsView.m中执行self.navigationController.title = @"Contacts";
时,它不会更改顶部栏的标题。
谢谢!
答案 0 :(得分:0)
我可能错了,但我认为您没有使用正确的方法在导航控制器中设置视图控制器。
你这样做:
[navigationController.view addSubview:[tabsView view]];
我会用:
[navigationController setViewControllers:[NSArray arrayWithObject:tabsView] animated:NO];
答案 1 :(得分:0)
两件事。
建议不要在导航控制器中嵌入UITabBarController
。可以在UITabBarController
中嵌入UINavigationController。我知道将UITabBarController
嵌入UINavigationController
会很“很高兴”,但您可能需要重新考虑您的设计,以便遵循iOS设计理念。
不要将子视图添加到appDelegate中的窗口,而是尝试将您正在使用的控制器添加到窗口的rootViewController属性,即
self.window.rootViewController = navigationController;