Objective c 如何使子类引用其超类的XIB?
我得到了一个Objective c 如何使子类引用其超类的XIB?,objective-c,xcode4.5,Objective C,Xcode4.5,我得到了一个BaseClassUIViewController类。它工作得很好基类具有BaseClass.xib 然后我创建了这个基类的一个子类 结果没有一个插座连接 我把 是的,就这样。它叫。我不确定aDecoder是什么。我认为这是childClass的XIB的一种表示,它并不存在。我想用super的xib初始化super - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
BaseClass
UIViewController类。它工作得很好<代码>基类具有BaseClass.xib
然后我创建了这个基类的一个子类
结果没有一个插座连接
我把
是的,就这样。它叫。我不确定aDecoder是什么。我认为这是childClass的XIB的一种表示,它并不存在。我想用super的xib初始化super
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
从来没有人打过电话
事实上,我自己也很困惑。当我们有xib时,似乎调用的是-(id)initWithCoder:(NSCoder*)aDecoder
。所以我想知道initWithNibName的作用是什么
我试过了
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithNibName:NSStringFromClass([super class]) bundle:nil];
return self;
}
-(id)initWithNibName:(NSString*)nibName bundle:(NSBundle*)nibBundle
是UIViewController
的指定初始值设定项。所以在你继承的班级里
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:@"BaseClass" bundle:nibBundleOrNil];
if (self) {
}
return self;
}
每当苹果将一个初始值设定项标记为指定的初始值设定项时,其他初始值设定项只会指向指定的初始值设定项。您不需要实现其他初始值设定项
NIB加载使用initWithCoder,这就是为什么加载NIB时会调用它 如果要更改对象的初始化方式或进行其他初始化,只需重写init方法。当从xib加载
UIViewController
(或任何内容)时,调用init
方法时,您的插座尚未连接
加载xib中的所有对象并设置连接后,将调用awakeFromNib。实现它以查看是否所有内容都已正确加载(应该)。如何初始化视图控制器?使用
UIViewController
的initWithNibName:bundle:
或NSBundle
的loadNibNamed:owner:
?
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:@"BaseClass" bundle:nibBundleOrNil];
if (self) {
}
return self;
}