ios 团队开发-UITabbarController整合多个storyboard的controllers

在一个tabbarController中,该如何整合 来自多个storyboard的controller页面呢?
为什么会有多个storyboard呢?多人开发的工程中,根据不同的功能业务模块,可以使用多个storyboard,每个storyboard完成自己模块的controller或其他视图的编写:最后写完之后,只需要先找到对应的storyboard,然后在该storyboard中找到你所需的controllers即可。

那么如何整合3个或多个storyboard的controllers页面到一个tabbar上面呢?
直接上代码,慢慢解释

#import TabBarController.h
@interface TabBarController ()

@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    // 创建一个数组来保存controller对象
    NSMutableArray *vcs = [NSMutableArray arrayWithCapacity:3]; 

    UIStoryboard *main = [UIStoryboard storyboardWithName:@Main bundle:[NSBundle mainBundle]]; // 首先找到对应的storyboard
    UIStoryboard *main1 = [UIStoryboard storyboardWithName:@Main1 bundle:[NSBundle mainBundle]];
    UIStoryboard *main2 = [UIStoryboard storyboardWithName:@Main2 bundle:[NSBundle mainBundle]];

    // 根据storyboard和controller的storyboardID找到控制器
    UIViewController *vc1 = [main instantiateViewControllerWithIdentifier:@"one"];
    UIViewController *vc2 = [main1 instantiateViewControllerWithIdentifier:@"two"];
    UIViewController *vc3 = [main2 instantiateViewControllerWithIdentifier:@"three"];

    [vcs addObject:vc1];
    [vcs addObject:vc2];
    [vcs addObject:vc3];

    // 用当前的viewController数组替换原本的tabbarControlle的viewControllers数组
    [self setViewControllers:vcs animated:NO];
}

当然,使用 这些语句之前,需要给ViewController设置标识符:
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值