1.新建项目
2.删除项目自带的ViewController和Main.storyboard,并且在target里面General的Main Interface删除Main
3.新建MyTabBarController,继承自UITabBarController
4.新建两个storyboard,命名为AStoryboard和BStoryboard
5.为两个storyboard添加导航
6.新建两个控制器,命名为AViewController和BViewController,继承自UIViewController
7.将故事板即AStoryboard和AViewController绑定以及BStoryboard和BViewController绑定,并且在A故事板上拉一个label,设置text为A,便于切换界面的时候显示,也可设置不同的背景色以便区分A和B故事板
8.在MyTabBarController.m里面写代码将控制器加入tabBar
UINavigationController *naviConA = [[UIStoryboard storyboardWithName:@"AStoryboard" bundle:[NSBundle mainBundle]]instantiateInitialViewController];
naviConA.title = @"A";
[self addChildViewController:naviConA];
UINavigationController *naviConB = [[UIStoryboard storyboardWithName:@"BStoryboard" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
naviConB.title = @"B";
[self addChildViewController:naviConB];
9.在AppDelegate.m写启动
在引入头文件后,写如下启动代码
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
MyTabBarController *myTabBar = [[MyTabBarController alloc]init];
self.window.rootViewController = myTabBar;
[self.window makeKeyAndVisible];
10.运行发现项目崩了,错误显示界面
这是因为我忘了在属性面板勾选“ Is Initial View Controller”
11.勾选以后,运行显示效果如下