Objective c initWithNibName到底做什么?
我猜它将加载CustomCell并将TestController设置为所有者。如果是: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”绑定:
[[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];