第一种类型界面

// 引入四个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是根视图。具体情况具体分析,这里所说的第一种界面,是指当前主流界面。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值