0

So, I am using a RootViewController from which you can display first ViewController Categories and then from Categories you display next ex. Music

RootViewController -> Categories -> Music

In RootViewController I use this

[self presentModalViewController:categoriesView animated:NO]; 

to present the modal view and then dismiss it from Categories with

[self dismissModalViewControllerAnimated:NO];

From Categories to Music I use again

[self presentModalViewController:fruitView animated:NO]; 

to present the Music modal view and then dismiss it in music with again the same as above.

Is there a possibility to dismiss two modal views? I want a method that leads from Music back to RootViewController, dismisses both last modal views.

Any ideas?

Twelve47
  • 3,924
  • 3
  • 22
  • 29

7 Answers7

3

Hi Use this Following code[[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];

1

Are you sure you want to use modal views for this? It sounds like what you're trying to do is better solved with a UINavigationController, where you can push and pop view controller's in a stack (and there's a popToRootViewControllerAnimated: message you can use).

This is how drill-down navigation is idiomatically handled in iOS (in the iPod, Notes, Contacts, Videos, Photos apps for example).

There's sample code for this in Xcode, I believe.

vicvicvic
  • 6,025
  • 4
  • 38
  • 55
0

UINavigationController has a popToRootViewControllerAnimated: method, which per the documentation:

Pops all the view controllers on the stack except the root view controller and updates the display.

peterp
  • 3,145
  • 1
  • 20
  • 24
0

Use popToRootViewControllerAnimated method of UINavigationController.

[self.navigationController popToRootViewControllerAnimated:YES];
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
0

What you're talking about here, going from more general to more specific views, is better handled with a UINavigationController pushing and popping views. These are the views which slide left and right on the screen. Pushing means it slides in from the right (and shows a new, more specific view). Popping slides back to the right and shows a more general view.

A modal view controller is the one that slides in from the bottom of the screen. Look at the iPod app on your device for the way to handle this.

nevan king
  • 112,709
  • 45
  • 203
  • 241
0

I use a nice utility method to do this... see here:

How to dismiss the two or more dismissModalViewController?

Community
  • 1
  • 1
Steve N
  • 2,667
  • 3
  • 30
  • 37
-1

Use This, In music view write this for dissmiss 2 view .

[RootViewController dismissModalViewControllerAnimated:YES];

Here RootViewController is an object of RootViewController Hope this will help u.

Vijay
  • 997
  • 1
  • 12
  • 27