zoukankan      html  css  js  c++  java
  • 加载storyboard和xib文件

        // 加载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是不会被调用的。 

    IOS开发
  • 相关阅读:
    如何将数据库中已有表导入到powerDesigner生成pdm文件
    Delphi TcxTreelist 表格左边总是缩进去 ,好像有偏移 解决方法
    HTML、CSS、JS对unicode字符的不同处理
    老生常谈ajax
    浅谈javascript面向对象
    HTML5原生拖放实例分析
    一个小动画,颠覆你的CSS世界观
    布局神器display:table-cell
    javascript 日常总结
    G2 2.0 更灵活、更强大、更完备的可视化引擎!
  • 原文地址:https://www.cnblogs.com/luanmage/p/4626209.html
Copyright © 2011-2022 走看看