這取自我的一個應用程序。正如你所說,你不應該子類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
啊。它可以提供一個委託或任何其他。聰明。謝謝。 –