创建若干个子视图控制器(并列关系)
创建UITabBarItem实例,赋值给相应的子视图控制器创建一个数组,将已创建的子视图控制器添加到数组中创建UITabBarController实例tabBarController.viewControllers = viewControllers添加到window的rootViewController中- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; HomeViewController *ctrl1 = [[HomeViewController alloc]init]; UITabBarItem *homeItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed: @""] tag:1]; ctrl1.tabBarItem = homeItem; MessageViewController *ctrl2 = [[MessageViewController alloc]init]; UITabBarItem *msgItem = [[UITabBarItem alloc] initWithTitle:@"新闻" image:[UIImage imageNamed: @""] tag:2]; ctrl2.tabBarItem = msgItem; HistoryViewController *ctrl3 = [[HistoryViewController alloc]init]; UITabBarItem *historyItem = [[UITabBarItem alloc] initWithTitle:@"历史" image:[UIImage imageNamed: @""] tag:3]; ctrl3.tabBarItem = historyItem; SearchViewController *ctrl4 = [[SearchViewController alloc]init]; UITabBarItem *searchItem = [[UITabBarItem alloc] initWithTitle:@"搜索" image:[UIImage imageNamed: @""] tag:4]; ctrl4.tabBarItem = searchItem; SettingViewController *ctrl5 = [[SettingViewController alloc]init]; UITabBarItem *settingItem = [[UITabBarItem alloc] initWithTitle:@"设置" image:[UIImage imageNamed: @""] tag:5]; ctrl5.tabBarItem = settingItem; NSArray *controllers = @[ctrl1,ctrl2,ctrl3,ctrl4,ctrl5]; UITabBarController *tabController = [[UITabBarController alloc]init]; [tabController setViewControllers:controllers animated:YES]; self.window.rootViewController = tabController; return YES;}