UIViewController -viewDidLoad not being called

前端 未结 10 2133
感动是毒
感动是毒 2020-12-09 07:52

Being new to Cocoa, I\'m having a few issues with Interface Builder, UIViewController and friends.

I have a UIViewController s

相关标签:
10条回答
  • 2020-12-09 08:46

    Simply use

    - (void)viewDidAppear:(BOOL)animated{ 
            [super viewDidAppear:animated];
            //Your Code here
      }
    

    instead of the viewDidLoad method.

    0 讨论(0)
  • 2020-12-09 08:48

    Another reason, somewhat obvious in retrospect: if viewController.view is set in code, then the viewDidLoad event will not trigger.

    0 讨论(0)
  • 2020-12-09 08:55

    RE: SOLUTION FOUND!!!!!

    Indeed that seems to be a working solution, however the real trick is not in setting the view.hidden property to NO, what makes the view load from the nib file is the calling of the UIViewController's view method, the view only actually gets loaded from the nib when the view method is called for the first time.

    In that sense, a simple [viewController view] message would force the view to load from the nib file.

    0 讨论(0)
  • 2020-12-09 08:56

    Check your run log for errors. Almost certainly, the NIB is not loading, and there should be an error to that effect. The most likely cause for that is failure to put it in the bundle. Look in your "Copy Resources" build phase and make sure that the XIB is actually being copied. Build for the simulator, and go down into the build directory and make sure that the NIB is in the .app bundle.

    0 讨论(0)
提交回复
热议问题