UIViewController init vs initWithNibName:bundle:

僤鯓⒐⒋嵵緔 提交于 2019-12-05 08:53:34

There seems to be something magical about the name PreferencesController. I just had the exact same problem. Renaming my class (and xib) to something else solved the problem.

Edit: I was incorrect, nib files should load automatically with alloc init if they are named the same as the controller.

What is your File's Owner in Interface Builder? The default behavior can be modified by changing this value.

Cody A. Ray

You have to override initWithNibName:bundle: instead of init because this is the "designated initializer". When you load this from a Nib file, this is the creator message being called.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}

Resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!