这取自我的一个应用程序。正如你所说,你不应该子类UINavigationController
,而是你使用它们,你可以在UINavigationController's
上添加viewcontroller。然后,在设置每个UINavigationController
中的根视图控制器之后,将UINavigationController
添加到UITabBarController
(phew!)。
因此,每个选项卡将“指向”一个UINavigationController
,它具有一个常规viewcontroller作为根视图控制器,它是根视图控制器(您添加的视图控制器),当用(可选)导航栏在顶部。
UITabBarController *tvc = [[UITabBarController alloc] init];
self.tabBarController = tvc;
[tvc release];
// Instantiates three view-controllers which will be attached to the tabbar.
// Each view-controller is attached as rootviewcontroller in a navigationcontroller.
MainScreenViewController *vc1 = [[MainScreenViewController alloc] init];
PracticalMainViewController *vc2 = [[PracticalMainViewController alloc] init];
ExerciseViewController *vc3 = [[ExerciseViewController alloc] init];
UINavigationController *nvc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
UINavigationController *nvc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
UINavigationController *nvc3 = [[UINavigationController alloc] initWithRootViewController:vc3];
[vc1 release];
[vc2 release];
[vc3 release];
nvc1.navigationBar.barStyle = UIBarStyleBlack;
nvc2.navigationBar.barStyle = UIBarStyleBlack;
nvc3.navigationBar.barStyle = UIBarStyleBlack;
NSArray *controllers = [[NSArray alloc] initWithObjects:nvc1, nvc2, nvc3, nil];
[nvc1 release];
[nvc2 release];
[nvc3 release];
self.tabBarController.viewControllers = controllers;
[controllers release];
这是我从一个视图 - 控制到另外一个(这是由在实现代码如下轻敲细胞做,但你看到可以使用pushViewController方法无论你想)。
(这是从应用程序的另一部分截取)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.detailedAnswerViewController == nil) {
TestAnsweredViewController *vc = [[TestAnsweredViewController alloc] init];
self.detailedAnswerViewController = vc;
[vc release];
}
[self.navigationController pushViewController:self.detailedAnswerViewController animated:YES];
}
的self.navigationcontroller
属性当然在其上的的UINavigationController层次结构被推每个视图控制器设置的。
如何管理PracticalMainViewController和PracticalSecondaryViewController之间的交互?关键值观察? –
在我的情况下,PracticalMainViewController是一个UITableView,我在didSelectRowAtIndexPath中使用[self.navigationController push ...]来推动一个新的viewcontroller;这是回答这个问题还是你的意思是我如何在它们之间传递数据? – LuckyLuke
啊。它可以提供一个委托或任何其他。聪明。谢谢。 –