I have a view hierarchy like this:
MainView -> SubView (PresentingView) -> ModalViewc (all subclasses of UIViewController)
By clicking a button in the ModalView I want to remove both the ModalView and the PresentingView so I can return to the MainView which will then present ModalViewX:
MainView -> ModalViewX (all subclasses of UIViewController)
[[self presentingViewController] removeFromParentViewController];
The above code simply dismisses the ModalView but the PresentingView remains.
My final goal is to have the ModalView button perform some concluding logic before returning to the MainView. Clicking the button would basically do the following actions:
- Concluding logic
- Remove self(ModalView) and PresentingView (bonuspoints if I can animate the removal)
- Tell MainView to present ModalViewX
(maybe I will have to call step 3 in the ModalView -> viewDidUnload method somehow)
Suggestions for how to do this?
First, embed your whole project in a UINavigationController with the
MainViewControlleras the rootview. To get from theMainViewControllerto theSubViewControllerdo this:This will get you to the next UIViewController. If you want to pass information, just set
vc setVariable:.To get back to the rootview, simply call
[self.navigationController popToRootViewControllerAnimated:YES]The other way is to use segues, where you
CTRL+dragfrom the button to the next UIViewController. The logic to be done should then be set in the method- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender, where the destionationcontroller issegue.destinationViewController.That way, you can also add your custom animation by setting the seguestyle to custom, and subclassing
UISegue.