Question

Reading the documentation on the changes to UIViewControllers in iOS, I trying to figure out how the interaction between presenting modal view controllers works inside of a custom container view controller. Ultimately, what I would like to be able to do is reliably walk through a chain of presented view controllers, even if some of those controllers are being presented by child view controllers.

(I am working on a library, not on an app, so I am not creating the hierarchies I will be interacting with. I am simply trying to ensure that my library will work correctly within different types of hierarchies.)

So my question is boils down to, what happens when someone tries to present a view controller from a child view controller?

[childViewController presentViewController:viewController animated:YES completion:nil];

Since a presented view controller is intended to "take over" interaction until it is dismissed, it would make sense to me that the presentation request would be forward to its parent (or actually, up the chain of parentViewControllers until it reaches a view controller with no parentViewController) and then be displayed from that view controller. Otherwise, it seems as if the developer could do things like present modal view controllers from two different children, etc. which seems to me problematic. (Which presented view controller would take precedence, for example?).

Furthermore, if the above were true, it seems like it would have some implications. If the parent view controller is displaying a presented view controller, what would this return?

[childViewController presentedViewController];

Would it be nil because the parent is displaying it? Or could this request be forwarded to the parent, so that the parentViewController and any of its childViewControllers would all have the same results?

Anyway, I have a sample project ready to go to start running some scenarios, but I am curious if there is any documentation I have missed? Or if someone already knows about the way that this interaction takes place?

Was it helpful?

Solution

I worked on a container view controller a while ago and found out that the default implementation checks if parentViewController exists, and if it does it passes the message on to the parent.

I couldn't find any documentation on it, so you can't rely on it 100%.

OTHER TIPS

Dr.Touch has an excellent post exactly on that:

http://www.cocoanetics.com/2012/04/containing-viewcontrollers/

it's a must read if you're into View Controller Containers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top