多级视图控制器的创建

UITabBarController+UINavigationController+UIViewCOntroller,多级控制器的创建。

#pragma mark - 创建视图控制器
- (void) createViewControllers {

//1) 创建4个视图控制器
TrendsViewController *trendsVC = [[TrendsViewController alloc] init];
FindViewController *findVC = [[FindViewController alloc] init];
MessageViewController *messageVC = [[MessageViewController alloc] init];
MyViewController *myVC = [[MyViewController alloc] init];
//2) 将上述的4个视图控制器添加到一个数组中
NSArray *viewControllerArrays = @[ trendsVC, findVC, messageVC,myVC ];

//3) 设置title
NSArray *titleArray = @[ @"动态", @"发现", @"消息", @"我的"];

//4) 使用一个空的可变数组存储导航栏
NSMutableArray *navigationArray = [NSMutableArray array];

//5) for循环创建导航栏
for (int i = 0; i < viewControllerArrays.count; i++) {

    //a) 获取UIViewController
    UIViewController *viewCtrl = viewControllerArrays[i];
    //b) 设置标题
    viewCtrl.title = titleArray[i];

    //c) 设置导航栏
    //说明:第0个导航栏做特殊处理,使用自定义的
    if (i == 0) {
        //1) 自定义导航栏
        TrendsNavigationController *trendsNavigation = [[TrendsNavigationController alloc] initWithRootViewController:viewCtrl];
        //2) 添加到数组中
        [navigationArray addObject:trendsNavigation];
    } else {
        //1) 系统导航栏
        UINavigationController *navigationCtrl = [[UINavigationController alloc] initWithRootViewController:viewCtrl];
        //2)添加到数组中
        [navigationArray addObject:navigationCtrl];
     }
    }

    //6) 使用标签控制器来控制这些导航栏
  self.viewControllers = navigationArray;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值