Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在UITabBarController中制作NavigationRootViewController_Iphone_Ios_Uinavigationcontroller_Uitabbarcontroller - Fatal编程技术网

Iphone 如何在UITabBarController中制作NavigationRootViewController

Iphone 如何在UITabBarController中制作NavigationRootViewController,iphone,ios,uinavigationcontroller,uitabbarcontroller,Iphone,Ios,Uinavigationcontroller,Uitabbarcontroller,我有一个选项卡栏控制器与5 UIViewController连接。它连接正确。但是我想为每个UIViewController创建NavigationRootViewController。如何制作它们?您好,这说明了如何使用Interface builder在UItabBarController的选项卡中添加UINavigationController - (void)setupViewControllers { tabBarController = [[UITabBarControlle

我有一个选项卡栏控制器与5 UIViewController连接。它连接正确。但是我想为每个UIViewController创建NavigationRootViewController。如何制作它们?

您好,这说明了如何使用Interface builder在UItabBarController的选项卡中添加UINavigationController

- (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]
等。感谢您的帮助,我可以做到。