Iphone 如何在UITabBarController中制作NavigationRootViewController
我有一个选项卡栏控制器与5 UIViewController连接。它连接正确。但是我想为每个UIViewController创建NavigationRootViewController。如何制作它们?您好,这说明了如何使用Interface builder在UItabBarController的选项卡中添加UINavigationControllerIphone 如何在UITabBarController中制作NavigationRootViewController,iphone,ios,uinavigationcontroller,uitabbarcontroller,Iphone,Ios,Uinavigationcontroller,Uitabbarcontroller,我有一个选项卡栏控制器与5 UIViewController连接。它连接正确。但是我想为每个UIViewController创建NavigationRootViewController。如何制作它们?您好,这说明了如何使用Interface builder在UItabBarController的选项卡中添加UINavigationController - (void)setupViewControllers { tabBarController = [[UITabBarControlle
- (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];
}
1)将选项卡栏控制器添加到主窗口2) 将选项卡栏项目内的ViewController替换为UINavigationController
3) 将ViewController设置为相应UINavigationController的rootViewController如果无法对自动删除的对象调用
release
,程序将崩溃。所以请检查[firstNavcontroller release]代码>,[secondNavcontroller release]
等。感谢您的帮助,我可以做到。