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

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

那么如何整合3个/或多个storyboard的controllers页面到一个tabbar上面呢?

直接上代码,慢慢解释 :

1.首先创建一个类,继承自

?
1
UITabBarController

 

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//
//  TabBarController.h
//  Aiyu
//
//  Created by http://blog.csdn.net/yangbingbinga on 14/10/24.
//  Copyright (c) 2014年 http://blog.csdn.net/yangbingbinga. All rights reserved.
//
 
# import <uikit uikit.h= "" >
 
@interface TabBarController : UITabBarController
 
@end
</uikit>
2.实现文件:

 

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
//  TabBarController.m
//  Aiyu
//
//  Created by http://blog.csdn.net/yangbingbinga on 14/10/24.
//  Copyright (c) 2014年 http://blog.csdn.net/yangbingbinga. All rights reserved.
//
 
# import TabBarController.h
 
@interface TabBarController ()
 
@end
 
@implementation TabBarController
 
- ( void )viewDidLoad {
     [ super viewDidLoad];
     NSMutableArray *vcs=[NSMutableArray arrayWithCapacity: 3 ]; //创建一个数组来保存controller对象
     
     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]];
     
     
     UIViewController *vc1=[main instantiateViewControllerWithIdentifier: @xiaoenai ]; //根据storyboard和controller的storeId找到控制器
     UIViewController *vc2=[main1 instantiateViewControllerWithIdentifier: @xinqing ];
     UIViewController *vc3=[main2 instantiateViewControllerWithIdentifier: @miyu ];
     
     [vcs addObject:vc1];
     [vcs addObject:vc2];
     [vcs addObject:vc3];
     
     [self setViewControllers:vcs animated:NO]; //用当前的viewController数组替换原本的tabbarControlle的 viewControllers数组
}
 
@end
当然,使用 这些语句之前,需要给ViewController设置标识符:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值