我有一个标签栏控制器可以连接5个UIViewController。它连接正确。但我想为每个UIViewController制作NavigationRootViewController。如何制作它们?
答案 0 :(得分:0)
嗨这解释了如何使用Interface builder在UItabBarController的选项卡中添加UINavigationController。
1)将标签栏控制器添加到主窗口
2)用UINavigationControllers替换Tab Bar项目中的viewControllers
3)将viewControllers设置为相应UINavigationControllers的rootViewController
答案 1 :(得分:-1)
- (void)setupViewControllers
{
tabBarController = [[UITabBarController alloc] init];
HomeViewController *mainViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UINavigationController *firstNavController = [[[UINavigationController alloc] initWithRootViewController:mainViewController] autorelease];
mainViewController.shouldReloadCount = YES;
[mainViewController release];
MapViewController *currentLocationController = [[MapViewController alloc] initWithNibName:@"MapView" bundle:nil];
UINavigationController *secondNavController = [[[UINavigationController alloc] initWithRootViewController:currentLocationController] autorelease];
[currentLocationController release];
FavoritesViewController *favouriteController = [[FavoritesViewController alloc] initWithNibName:@"FavoritesViewController" bundle:nil];
UINavigationController *thirdNavController = [[[UINavigationController alloc] initWithRootViewController:favouriteController] autorelease];
[favouriteController release];
AllNotificationsViewController *notifController = [[AllNotificationsViewController alloc] initWithNibName:@"AllNotificationsViewController" bundle:nil];
UINavigationController *fourthNavController = [[[UINavigationController alloc] initWithRootViewController:notifController] autorelease];
[notifController release];
SettingsViewController *settingsController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
UINavigationController *fifthNavController = [[[UINavigationController alloc] initWithRootViewController:settingsController] autorelease];
[settingsController release];
tabBarController.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, thirdNavController,fourthNavController,fifthNavController, nil];
firstNavController.tabBarItem.image = [UIImage imageNamed:@"house.png"];
firstNavController.tabBarItem.title = @"Home";
secondNavController.tabBarItem.image = [UIImage imageNamed:@"map.png"];
secondNavController.tabBarItem.title = @"Locator";
thirdNavController.tabBarItem.image = [UIImage imageNamed:@"fav.png"];
thirdNavController.tabBarItem.title = @"Favorites";
fourthNavController.tabBarItem.image = [UIImage imageNamed:@"profile.png"];
fourthNavController.tabBarItem.title = @"Activities";
fifthNavController.tabBarItem.image = [UIImage imageNamed:@"settings.png"];
fifthNavController.tabBarItem.title = @"Settings";
//[self.view addSubview:tabBarController.view];
[[[UIApplication sharedApplication].windows objectAtIndex:0] addSubview:tabBarController.view];
}