You hit into a limitation of dismissModalViewController
: it will remove all of your modal views (source):
If you present several view controllers in succession, and thus build a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
What you could do is using a UINavigationController
and simply push/pop controllers on to it according to your requirements.
Alternatively, you could simply display the views managed by the various controllers you have by directly calling addSubview
on your top view and making sure they cover the whole screen and that the managing controller is correctly retained/released (the view is automatically when you add/remove it to another view).
As a hint, you could do it like this:
where you have presentModal...
, use addSubview
;
where you have dismiss...
, use removeFromSuperview
;
store a reference to any view controller whose view you manage like I suggest here in retain
/strong
property.