In my app I have the following configuration to open my view controllers:
When I write "pushViewController" I use a navigation controller, and when I write "present" I use a presentModalViewController
.
firtsView -> (pushviewcontroller) -> secondOneView -> (present) -> thirdOneView -> (present) -> fourthView
firstView -> (pushviewcontroller) -> secondTwoView -> (present) -> thirdTwoView
This is the scheme of my app to organize my view controllers. Then my question is:
What's the way to return from "fourthView" (that is when I go back from "fourthView") to "secondTwoView"?
Is there a way to do it?
Yes there are.
The UIViewController
offers different methods to dismiss a view controller depending on if you presented it modally or not. These are :
-(void)dismissModalViewControllerAnimated:(BOOL)animated; // modal
-(void)dismissViewControllerAnimated:(BOOL)flag
completion:(void (^)(void))completion;
You will need to dismiss them one by one. Also, take time to read the View Programming Guide from Apple.
Using a UINavigationController
you may pop to any view controller using :
-(NSArray *)popToViewController:(UIViewController *)viewController
animated:(BOOL)animated;
Alternatively, another method let you pop just one :
-(UIViewController *)popViewControllerAnimated:(BOOL)animated;