我在从 nib 加载子类 UIViewController 时遇到了一些麻烦。我的 viewDidLoad 函数从未被调用。
父类(super class)没有nib,但子类各有自己的nib。即
@interface SuperClass : UIViewController {
}
@end
@interface SubClass : SuperClass{
}
@end
@implementation SubClass
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad{
// Never called
}
View 是从 nib 加载的,如下所示:
SubClass *scvc = [[SubClass alloc] initWithNibName:@"SubClass" bundle:nil];
[self.navigationController pushViewController:scvc animated:YES];
[scvc release];
有一个同名的 nib 文件,它的文件所有者的类设置正确。
viewDidLoad 未在子级或 super 级中调用。有什么想法吗?
最佳答案
你说你在父类(super class)中用代码创建 View (使用 loadView),但试图在子类中使用 nib?
根据 UIViewController 文档(强调我的)
If you specify views using a nib file, you must not override loadView but should instead create a nib file in Interface Builder...
看起来你可能在那里有冲突。作为测试,在您的父类(super class)中注释掉 loadView 方法,看看它会把您带到哪里。
关于ios - viewDidLoad 从未在子类 UIViewController 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8279908/