UINavigationController和Storyboard的应用

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.勾选以后,运行显示效果如下
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值