zoukankan      html  css  js  c++  java
  • 从xib/nib加载UIViewController/或其子类

    【之所以】
    xib、nib文件目的在于为控件快速定位
    这里仅针对UIViewController和其子类

    【How】
    这里整理并描述两种方式的使用:
    1、UIViewController initWithNibName
    主要代码如下:
        StarterController *starter = [[StarterController alloc] initWithNibName:@"StarterController" bundle:nil];
        NSLog(@"starter = %@" ,starter);
        if (starter)
        {
            NSLog(@"%@ parent controller is %@" ,starter ,starter.parentViewController);
            NSLog(@"%@ nav controller is %@" ,starter ,starter.navigationController);

        }

    注意参数bundle,暂时不知道怎么获取,后续解答。

    StarterController.xib,如图,此处File Owner ,Class = StarterController,此类继承UIViewController


    2、NSBundle loadNibNamed
    主要代码如下:
        NSArray *niblets = [[NSBundle mainBundle] loadNibNamed:@"sample" owner:self options:NULL];
        for (id theObject in niblets)
        {
            if ([theObject isKindOfClass:[UIViewController class]])
                [self.navigationController pushViewController:theObject animated:YES];
        }

    sample.xib,如图,特别注意File Owner,这个类是NSObject


    【其他】
    在实践中,出现一个问题:“loaded the...nib but the view outlet was not set”
    解决参见:
    http://hi.baidu.com/sushii/blog/item/17df66084dd7abdd3ac763bb.html


    无论生活、还是技术,一切都不断的学习和更新~~~努力~
  • 相关阅读:
    Python_01安装与配置
    数据库的事务日志已满,起因为"LOG_BACKUP"
    百度网盘视频在线倍速播放的方法——Js 一行代码实现
    Socket里Client和Server
    Python自动化执行遍历点击列表的前20行每一行
    pyhton判断闰年
    Python程序结构-包
    试题 历届试题 错误票据
    试题 历届试题 剪格子
    试题 历届试题 打印十字图
  • 原文地址:https://www.cnblogs.com/GoGoagg/p/2076456.html
Copyright © 2011-2022 走看看