第一種類型界面

// 引入四個controller
#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是根視圖。具體情況具體分析,這裏所說的第一種界面,是指當前主流界面。

發佈了22 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章