UIViewController -viewDidLoad not being called
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.
Ok, I have a partial answer - maybe the gurus can explain some more. The problem is:
[self.navigationController pushViewController:myViewController animated:YES];
Looking more closely, in this case self.navigationController
is nil - so the push message is going no-where.
Instead, if I send:
[self.view addSubview:self.myViewController.view];
Then the view appears and -viewDidLoad
is called.
I'm not entirely sure why self.navigationController
is not set in this instance - the only thing I can think of is that self
is a subclass of UIViewController
rather than UITableViewController
(where the pushViewController
code came from).
Also, silently allowing messages to go to nil seems like a bad idea, although these answers say otherwise. See also my question here.
Final edit:
Answers in comments below, I've realised the display function that I was actually after (given myViewController is modal) is:
[self presentModalViewController:myViewController animated:YES];
Thanks everyone for their helpful responses.