#import "ActivityViewController.h"
#import "MovieViewController.h"
#import "CinemaViewController.h"
#import "MineViewController.h"
@interface AppDelegate ()<UITabBarControllerDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
ActivityViewController *acvc = [[ActivityViewController alloc] init];
MovieViewController *movc = [[MovieViewController alloc] init];
CinemaViewController *civc = [[CinemaViewController alloc] init];
MineViewController *mivc = [[MineViewController alloc] init];
acvc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"活動" image:[UIImage imageNamed:@"activity"] tag:101];
acvc.view.backgroundColor = [UIColor redColor];
movc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"電影" image:[UIImage imageNamed:@"movie"] tag:101];
movc.view.backgroundColor = [UIColor blueColor];
civc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"影院" image:[UIImage imageNamed:@"cinema"] tag:101];
civc.view.backgroundColor = [UIColor yellowColor];
mivc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"user"] tag:101];
mivc.view.backgroundColor = [UIColor orangeColor];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = @[acvc, movc, civc, mivc];
tbc.selectedIndex = 1;
tbc.navigationItem.title = @"電影";
tbc.delegate = self;
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:tbc];
self.window.rootViewController = nvc;
// Override point for customization after application launch.
return YES;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (tabBarController.selectedIndex == 0) {
tabBarController.navigationItem.title = @"活動";
}
if (tabBarController.selectedIndex == 1) {
tabBarController.navigationItem.title = @"電影";
}
if (tabBarController.selectedIndex == 2) {
tabBarController.navigationItem.title = @"影院";
}
if (tabBarController.selectedIndex == 3) {
tabBarController.navigationItem.title = @"我的";
}
}
說這麼多,其實表達的意思就是,根視圖是哪個的問題。一種是 navigationController是根視圖,另一種是tabBarController是根視圖。具體情況具體分析,這裏所說的第一種界面,是指當前主流界面。