加载storyboard和xib文件
2015-07-07 10:23
344 查看
// 加载storyboard UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Two" bundle:nil]; // 创建storyboard里面灰色的控制器 //找到shtoryboard里面设置的初始控制器 // UIViewController *vc = [storyboard instantiateInitialViewController]; // 从storyboard里面找出绑定标识的控制器 MJTwoViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"pink"]; self.window.rootViewController = vc;
2.通过xib加载
//nib文件初始化 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } //加载所有xib文件
NSArray* objects = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil]
//加载指定xib文件
ContactsTableViewCell *cell = [[[NSBundle mainBundle]loadNibNamed:@"ContactsTableViewCell" owner:nil options:nil] objectAtIndex:0]
3.xib布局文件初始化的两种方法
-(instancetype)initWithFrame:(CGRect)frame { self=[super initWithFrame:frame]; if (self) { //NIb加载会把xib文件加载到内存中,读取快,经常使用的xib文件可以使用nib加载, //Bundle加载,每次会从磁盘上加载,效率会慢一点 // self=[[[UINib nibWithNibName:@"MPListView" bundle:nil] instantiateWithOwner:self options:nil] lastObject]; self=[[[NSBundle mainBundle] loadNibNamed:@"MPListView" owner:self options:nil] objectAtIndex:0]; } return self; }
但是如果你使用initWithNibName调入Nib时,awakeFromNib是不会被调用的。
相关文章推荐
- leetCode(31):Combination Sum III 分类: leetCode 2015-07-07 10:23 163人阅读 评论(0) 收藏
- javascript笔记01:javascript入门介绍
- C++读取特定路径下文件目录及文件名称&&文件结构
- kubenetes環境搭建
- 【leetcode】Binary Tree Maximum Path Sum
- Hadoop
- [深入学习C#]完成异步委托的三种方式
- android 存储5种方式
- C#关于摄像头的使用
- chrome firefox 获取模拟微信浏览器
- 【后端】content type大全 from http://tool.oschina.net/commons
- Android5.0网络之ipv6
- H5页面中删除iPhone自带样式
- WEB前端面试题整理
- [SoapUI] context.expand 和 groovyUtils.getXmlHolder 有什么不一样
- Python连接PostgreSQL
- Jquery DataTable 回调函数说明及示例
- eclipse内存设置
- 自定义弹出框
- 使用POI转换word doc文件