I have an odd case — a view controller that creates its own view in loadView and which is then added to an existing view.
Here is the code that creates and adds the VC:
self.doneButtonViewController = [[DoneButtonViewController alloc] init];
[self.view addSubview:self.doneButtonViewController.view];
This code is executed in viewDidLoad of the “parent” VC.
The odd thing is that the viewWillAppear method of the added VC is never invoked (nor is viewDidAppear), but the viewWillDisappear method of the added VC is invoked (at the appropriate time), just as one would expect.
Any clue as to why viewWillAppear is not getting invoked?
The application isn’t aware of the subview’s view controller if you do this, you need to introduce view controller containment to make the root view controller aware. Doing so will handle any events like this.
Because
loadViewcould be called more than once pre iOS 6, I’d advise creating the view controller withininit, and then add the subview withinloadView. It should be like this:See “Implementing a Container View Controller” at http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html