I am using navigation bar on my application for reach next views in my iphone application.
in a stage of view I want reach back my first view.How can i do it please give me suggestion.Thanks.
There is a popToRootViewControllerAnimated: method that will remove all controllers from the stack and return the user to the first view controller.
See the Apple docs.
[self.navigationController popToRootViewControllerAnimated:YES];
This call will take you to the root of your view controllers
You need to use to go back to your previous view
[self dismissModalViewControllerAnimated:YES];
Hope it helps.
Related
I implemented 4 views in AppDelegate depends on requirement it will call the view.I called second(example) view then I pushed to the new view again I pushed to the other new view.I want to go back to the second(example) view. I implemented the code like this [self.navigationController popToRootViewControllerAnimated:YES]; but it is poping to previous view and again it go back to the second(example) view. Can any one tell me how it goes directly to the second(example) view.
Thanks in advance.
Instead of using popToRootViewController you need to use popToViewController like bellow
self.navigationController popToViewController:secondViewObj animated:YES];
You should use
popViewControllerAnimated:animated]
or
popToViewController:yourVC animated:animated]
Use [pushViewController:obj animated:NO].....
Though this will not pop your view, but it will push your view to obj that is object of FirstView.
This will simply work as you want, may be not technical way...:)
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?
Hi Use this Following code[[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];
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.
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.
Use popToRootViewControllerAnimated method of UINavigationController.
[self.navigationController popToRootViewControllerAnimated:YES];
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.
I use a nice utility method to do this... see here:
How to dismiss the two or more dismissModalViewController?
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.
I have a UINavigationController in my iPhone app controlling views in a drill-down fashion. I have 4 viewcontrollers that I pass through before I have a "Start over" button, where I would like the action to send the user back to the beginning of the view hierarchy.
[self.navigationController popToRootViewControllerAnimated:YES];
but it looks like it simply brings up a new rootviewcontroller on top of the current view controller.
Is there a way to pop the views back to the very beginning of the navigation drill down?
Any help would be great!
Many thanks,
Brett
Something else is going on here. I use popToRootViewControllerAnimated in on of my apps and it does exactly what you are after.
and if you want to goback direction to your desired view controller then use the code bellow-
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:3] animated:YES];
Here 'objectAtIndex:3' is the flow position(i.e. index) of your viewControllers. For the root it would be 0.
i'm working on iphone app which will show 4 buttons in first view. on click of a button, it will load a new view with navigation controller. this navigation controller view allows to travel upto 11 sub views. in 11th sub view, i've a reset button. on click of reset button, i've to go back to navigation controllers first view without traversing all the 11 views? is it possible to achieve it? if yes how? if no, what can be the solution?
You can also use the:
[self.navigationController popToRootViewControllerAnimated:YES];
u can use [self.navigationController popToViewController:objFirstViewController animated:YES] in the 11th view when you want to pop directly to the first view.
And if you are sure that you have to move to the first view and it is a rootviewcontroller then you can directly use
[self.navigationController popToRootViewControllerAnimated:YES];
Happy Coding..
I'm trying to set up an in app purchase and once the purchase has been made I need to reset the app to its initial launch state. I'm wondering if there is a way to dealloc all the view controllers inside of each navigation controller and reload the initial view that is displayed when the app launches.
Thanks in advance!
You can just
[self.navigationController setViewControllers:nil animated:NO];
(probably works, although not tested) however it is probably more useful to use:
[self.navigationController popToRootViewControllerAnimated:NO];
It is up to you to keep track of your navigation controllers, and to restore your starting view.