cyclingIsBetter
cyclingIsBetter

Reputation: 17591

IOS: open and close some view controllers

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?

Upvotes: 4

Views: 11704

Answers (3)

Zitao Xiong
Zitao Xiong

Reputation: 976

  1. in thirdOneView's viewcontroller, do dismissModalViewControllerAnimated:NO
  2. in secondOneView's viewcontroller do dismissModalViewControllerAnimated:NO again.
  3. in secondOneView's viewcontroller do popViewControllerAnimated:NO
  4. in firstView's Viewcontroller do pushViewController to secondTwoView

If you want some animation. I would suggest to do it manually by using CoreAnimation. Since

-(void)dismissViewControllerAnimated:(BOOL)flag
                      completion:(void (^)(void))completion;

is only available after iOS5.

Upvotes: 0

user971401
user971401

Reputation:

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;

Upvotes: 5

IPaPa
IPaPa

Reputation: 468

if you use presentViewController

i think you have to dismiss viewController one by one

but if you navigationcontroller only, then you can pop to viewController you want

Upvotes: 0

Related Questions