2012-03-12 37 views

回答

-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]; 

} 
+0

你无法在autoreleased对象上调用'release',程序将崩溃。所以请检查'[firstNavcontroller release];',[secondNavcontroller release]等等。 – Mat 2012-03-12 09:56:05

+0

@Mat oops ..我错过了。更新了我的答案。多谢,伙计。 – janusbalatbat 2012-03-12 10:08:27

+0

谢谢你的帮助,我可以做到这一点。 – WaiToNZa 2012-03-12 10:31:38

0

嗨这解释了如何使用接口生成器在UItabBarController中的选项卡内添加UINavigationController。

1)标签栏控制器添加到主窗口
2)UINavigationControllers
3更换标签栏里面的物品的viewControllers)设置viewControllers作为RootViewController的为各个UINavigationControllers

相关问题