Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c initWithNibName到底做什么?_Objective C_Xcode_Uitableview - Fatal编程技术网

Objective c initWithNibName到底做什么?

Objective c initWithNibName到底做什么?,objective-c,xcode,uitableview,Objective C,Xcode,Uitableview,我猜它将加载CustomCell并将TestController设置为所有者。如果是: 为什么在大多数示例代码中,我看到[[NSBundle mainBundle]loadNibNamed:@“CustomCell”所有者:测试控制器选项:nil];相反 [[NSBundle mainBundle]loadNibNamed:@“CustomCell”所有者:测试控制器选项:nil]和测试控制器=[[CustomCell alloc]initWithNibName:@“CustomCell”绑定:

我猜它将加载CustomCell并将TestController设置为所有者。如果是:

  • 为什么在大多数示例代码中,我看到
    [[NSBundle mainBundle]loadNibNamed:@“CustomCell”所有者:测试控制器选项:nil]
    ;相反

  • [[NSBundle mainBundle]loadNibNamed:@“CustomCell”所有者:测试控制器选项:nil]
    测试控制器=[[CustomCell alloc]initWithNibName:@“CustomCell”绑定:[NSBundle mainBundle]]自动释放]

  • 我尝试替换
    [[NSBundle mainBundle]loadNibNamed:@“CustomCell”所有者:测试控制器选项:nil]带有测试控制器=[[CustomCell alloc]initWithNibName:@“CustomCell”捆绑包:[NSBundle mainBundle]]自动释放]和我得到了错误。如果我使用后者,看起来插座仍然为
    nil


  • initWithNibName:bundle:
    是在
    UIViewController
    中声明的便利方法,可用于其子类。这将通过加载nib初始化视图控制器,可能在内部使用
    loadNibName:owner:options:
    方法


    initWithNibName:bundle:
    UIView
    及其子类不可用。因此,我们必须使用
    loadNibName:owner:options:
    来加载视图

  • 自定义单元格是
    UIView
    子类,因此使用
    loadNibName:owner:options:
  • 差别不大
    initWithNibName:bundle:
    是一种方便的初始化方法
  • 由于上述原因,您会出现错误

  • CustomCell是控制器,而不是视图。很抱歉没有说清楚。代码可以编译。如果CustomCell只是一个视图,我不会这么做
    theTestController = [[[CustomCell alloc]initWithNibName:@"CustomCell" bundle:[NSBundle mainBundle]]autorelease];