码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-01-25 08:43:43      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:tabbarcontroller整合   多个storyboard整合到tabba   

在一个tabbarController中,该如何整合 来自多个storyboard的controller页面呢?

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

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

直接上代码,慢慢解释 :

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

UITabBarController

//
//  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
2.实现文件:

//
//  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设置标识符:

见下图:

技术分享

原文出处http://blog.csdn.net/yangbingbinga/article/details/43106235





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

标签:tabbarcontroller整合   多个storyboard整合到tabba   

原文地址:http://blog.csdn.net/yangbingbinga/article/details/43106235

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!