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


    无论生活、还是技术,一切都不断的学习和更新~~~努力~
  • 相关阅读:
    vb动态创建控件
    100多个很有用的JavaScript函数以及基础写法汇总
    CodeFile与CodeBehind的区别
    asp.net防sql注入问题
    .NET创建目录和文件
    Asp.Net判断字符是否是数字
    Asp.Net随机中文汉字验证码
    禁用表单自动提示complete
    如何隐藏vs2005的起始页
    Asp.Net enableEventValidation
  • 原文地址:https://www.cnblogs.com/GoGoagg/p/2076456.html
Copyright © 2011-2022 走看看