user705917
user705917

Reputation: 1

dismissModalViewController multiple

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?

Upvotes: 0

Views: 1124

Answers (7)

user1025285
user1025285

Reputation:

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

Upvotes: 3

Vijay
Vijay

Reputation: 1016

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.

Upvotes: -1

Steve N
Steve N

Reputation: 2737

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

How to dismiss the two or more dismissModalViewController?

Upvotes: 0

nevan king
nevan king

Reputation: 113747

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.

Upvotes: 0

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

Use popToRootViewControllerAnimated method of UINavigationController.

[self.navigationController popToRootViewControllerAnimated:YES];

Upvotes: 0

vicvicvic
vicvicvic

Reputation: 6234

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.

Upvotes: 1

peterp
peterp

Reputation: 3165

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.

Upvotes: 0

Related Questions