Why viewDidAppear/viewWillAppear don't get called in a nested structure?
Please help, if you have any experience, our time is thicking.
I have this structure.
AppDelegate...
...Owns a _root ViewController (its view added to window)
...what owns the _main ViewController (its view added to _root's view)
...that has a Navigation cont开发者_开发百科roller (its view added to _main's view)
...then different viewControllers travels in this navigation stack.
But viewDidAppear/viewWillAppear methods don't get called in the innermost views. I don't know why.
As I read the documentation, it says "when added to a window". Are they works with windows? Don't think so. What should I do? Why don't these CRUTIAL methods get invoked?
Nesting view controllers is not allowed by the framework.
Yes, Apple does do it (for instance, by letting you embed one of your UIViewControllers in a tab/navigation view controller), but then they would be the ones to know how to do it.
It's still possible, by forwarding the right messages from your outer view controllers to your inner view controllers, but it takes a lot of care and is probably not very future-proof. It might save you this time, though! I.e. if you get a viewWillAppear in your _root, forward that to its sub-viewcontrollers, etc. If you manage to do this correctly for all appearances/disappearances, rotations, memory management then you're good.
Two years have passed and nesting view controllers is now supported: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html#//apple_ref/doc/uid/TP40007457-CH18-SW6
精彩评论