I have a tab
based application. One of the views
in it is pushing a modal view controller
. If I call self.presentingViewController
within a modal view controller
, it returns tab bar controller
, not the view controller
which is pushing it.
What am I missing here? Is there a reliable way to return a view controller
raising modal?
Thanks.
Is this an iPhone app? If so, that explains the confusion. On iPhone, the only presentation style is UIModalPresentationFullScreen
- which amounts to saying that on iPhone, the root view controller is always the presenting view controller. Well, in a tab bar interface, the UITabBarController's view is the root view controller.
You'll notice that on iPhone the modal view doesn't replace your view controller's view; it replaces the whole interface, meaning that it replaces the tab bar controller's view. This is because the tab bar controller really is the presenting view controller.
I'm guessing that on iPhone you really should not be sending presentViewController:
or presentModalViewController:
to a view controller contained by a tab bar controller. You should be sending it to the tab bar controller. The message is therefore being routed to the tab bar controller for you.
So, nothing interesting is going to happen with the value of presentingViewController
unless you're on an iPad. On an iPad, you can make the modal view replace the view controller's view. To do so, the modal view's modalPresentationStyle
must be UIModalPresentationCurrentContext
. And in that case, its presentingViewController
can in fact be the view that "pushes the modal view controller".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With