zoukankan      html  css  js  c++  java
  • initWithNibName 和 loadNibNamed 的区别

    UIViewController initWithNibName
    这时候是延迟加载
    主要代码如下:

                ShowViewController * showMessage = [[ShowViewController alloc]

                                                    initWithNibName:@"ShowViewController" bundle:nil];

                self.showViewController = showMessage;

                [showMessage release];

    这时候是延迟加载,这个View上的控件是 nil 的
    self.showViewController.show_Topic 
    只有到 需要显示时,才会不是 nil

     [saveViewController.view removeFromSuperview];

    [self.view insertSubview:showViewController.view atIndex:0];

    这时候 xib 文件的要求:
    NSBundle loadNibNamed
    实时加载。
    这时候的代码:

    NSArray * nib = [[NSBundle mainBundle] loadNibNamed:@"Save3ViewController" 

                                                              owner:self options:nil] ;

    self.showViewController = [nib lastObject];

    这时候的xib文件
    如果用 loadNibNamed 加载 initWithNibName 用到格式的 xib 文件,就会报错误:
    setValue:forUndefinedKey
    loaded the...nib but the view outlet was not set
    loadNibNamed和initWithNibName需要加载的xib文件是不一样的。initWithNibName需要加载的xib文件的File Owner应改是需要加载的类,
    而loadNibNamed需要加载的xib文件的File Owner为NSObject。
    http://www.cnblogs.com/GoGoagg/archive/2011/06/09/2076456.html
    when using loadNibNamed:owner:options:, the File's Owner should be NSObject, the main view should be your class type, and all outlets should be hooked up to the view, not the File's Owner.
    http://stackoverflow.com/questions/46220/iphone-app-crashing-error-question
    参考资料:

    从xib/nib加载UIViewController/或其子类
    http://www.cnblogs.com/GoGoagg/archive/2011/06/09/2076456.html

    iPhone App Crashing - Error Question
    http://stackoverflow.com/questions/46220/iphone-app-crashing-error-question
  • 相关阅读:
    手机网页唤醒app,
    h5 audio进度条
    js判断字符串与字符串相互包含,以及数组是否包含某个元素;
    vue cli 打包项目造成css背景图路径错误
    vue-cli webpack打包不.map文件,iview 项目打包完,图标路径有问题
    常用的活动榜单
    vue-cli的webpack模板项目配置文件分析,配置信息详解
    eclipse怎么debug项目
    什么是前置机,前置机的作用是什么
    jsp中连接数据库及实现增删改查
  • 原文地址:https://www.cnblogs.com/ghj1976/p/2521840.html
Copyright © 2011-2022 走看看