博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS中使用UITabBarController加Sotryboard混用实现Tab布局
阅读量:7223 次
发布时间:2019-06-29

本文共 1690 字,大约阅读时间需要 5 分钟。

hot3.png

方式一

  1. UITabBarController使用代码创建
  2. 4个UINavigationController使用Storyboard创建
  3. 在AppDelegate.m文件中发起UITabBarController调用

之所以不纯Storyboard实现是考虑到4个Storyboard文件如果放在一个Storyboard文件里,不利于管理与协同,还有稍一改用布局都得重新编译将会非常耗时。

自定义一个UITabBarController

#import 
@interface MainTabBarController : UITabBarController@end#import "MainTabBarController.h"@interface MainTabBarController ()
@end@implementation MainTabBarController- (void)viewDidLoad { [super viewDidLoad]; UINavigationController *homeNVC = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateInitialViewController]; UINavigationController *classifyNVC = [[UIStoryboard storyboardWithName:@"Category" bundle:nil] instantiateInitialViewController]; UINavigationController *cartNVC = [[UIStoryboard storyboardWithName:@"Cart" bundle:nil] instantiateInitialViewController]; UINavigationController *memberNVC = [[UIStoryboard storyboardWithName:@"Member" bundle:nil] instantiateInitialViewController]; self.viewControllers = @[homeNVC,classifyNVC,cartNVC,memberNVC];}@end

在AppDelegate.m中调用

@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    //    初始化TabBarController    MainTabBarController *rootViewController = [[MainTabBarController alloc] init];    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];    self.window.rootViewController = rootViewController;    [self.window makeKeyAndVisible];    return YES;}

方式二

在XCode7之后,还有一种做法是,使用Storyboard Reference来纯Storyboard来完成

详见:

遗憾的是这么好的特性,只能在iOS9下使用

因此,为了适配iOS8及以下的版本,还是老老实实地使用第一种方式实现

转载于:https://my.oschina.net/huangxiujie/blog/835967

你可能感兴趣的文章
Spring AOP动态获取函数参数中的值
查看>>
文件系统的简单操作
查看>>
xtrabackup 安装
查看>>
【数据结构作业心得】4-1 指针笔记
查看>>
NTT学习笔记
查看>>
online_judge_1051
查看>>
Mac与Widow下编译与运行java文件引入多个外部jar包
查看>>
通过Bottledwater同步PostgreSQL中的数据变化到Kafka消息队列
查看>>
洛谷P4112 最短不公共子串
查看>>
Every Tom,Dick and Harry. 不管张三李四。
查看>>
Ubuntu开机显示器报错
查看>>
怎样查w3wp.exe对应的IIS站点
查看>>
USACO 2.1
查看>>
Python--常用的内置函数
查看>>
RabbitMQ入门-消息订阅模式
查看>>
【ZJOI2016】线段树
查看>>
分子公司部署辅助域控步骤
查看>>
表现与数据分离(MV*)
查看>>
由理解Java访问权限而产生的感触
查看>>
loadrunner脚本中写入脚本输出log到外部文件,分析参数取值方式
查看>>