ios - viewDidLoad 从未在子类 UIViewController 中调用

标签 ios ios4

我在从 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/

相关文章:

ios - 有没有办法在设备之间共享应用程序配置?

ios - TextEdit 字段输入在 iOS10 上挂起

iPhone:通过本地通知增加应用程序徽章

iphone - UIBarButtonItem 操作不起作用。为什么?

iphone - 使用 UISegmentedControl 作为按钮

iphone - UIImagepickercontroller-视频超过10分钟问题-IOS

ios - 在 NSManagedObject 上调用 MR_createEntity 时出错

ios - 使用自适应布局的 UILabel 的不同字体大小

ios - 通过标签栏和按钮导航屏幕

iphone - 来自 NSDate 的日期名称?