-viewDidLoad not called in subclassed UIViewController

前端 未结 3 2046
长发绾君心
长发绾君心 2020-12-29 14:32

Have patience with me, I\'m still learning Cocoa Touch. Other -viewDidLoad not being called question was unrelated to my issue, I did search.

I have FooViewCo

3条回答
  •  没有蜡笔的小新
    2020-12-29 14:58

    And I've answered my own question, so this may help future folks. Since I see viewDidLoad has, as its three top Googles in my suggest, "viewDidLoad not called", "viewDidLoad not getting called", and "viewDidLoad not firing", I imagine this is a usual mistake...

    Changing:

    fooViewController = [[FooViewController alloc] init];
    if(![[NSBundle mainBundle] loadNibNamed:@"FooViewController" owner:fooViewController options:nil]) {
        DebugF(@"Failed to load FooViewController");
        return;
    }
    

    To:

    fooViewController = [[FooViewController alloc] initWithNibName:@"FooViewController" bundle:[NSBundle mainBundle]];
    

    Fixed the problem. Obviously a mistake in how I'm using Cocoa.

提交回复
热议问题