[课堂实践与项目]TabBarController (又称 标签控制器)的使用

1.本例中,我在view1使用了导航,view2中没有使用导航.这就做一个对比.


先看看 代理的.h文件吧

#import <UIKit/UIKit.h>

@class LCFirstViewController,LCSecondViewController;

@interface LCAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) LCFirstViewController *firstViewController;

@property (strong, nonatomic) LCSecondViewController *secondViewController;

.m文件

- (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];
    
    _firstViewController = [[LCFirstViewController alloc]init];
    
    _firstViewController.title =@"第一view";
    
    UINavigationController *firstNav = [[UINavigationController alloc]initWithRootViewController:_firstViewController];
    
    
    _secondViewController = [[LCSecondViewController alloc]init];
    
    NSArray *viewArr = [NSArray arrayWithObjects:firstNav,_secondViewController, nil];
    
    UITabBarController *tabBarVC = [[UITabBarController alloc]init];
    
    tabBarVC.viewControllers = viewArr;
    
    self.window.rootViewController = tabBarVC;
    
    
    [self.window makeKeyAndVisible];
    return YES;
}

总结:实现的原理是什么呢?

我们把一个带导航的控制器 和一个UiviewController 放到数组中,最终设置 tabbarVC的ViewCOntrollers 为该数组.

最后设置window的root为  tabbarVC,这样子  带导航不带导航的都有了~


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值