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.
Related
this if my first post so please be gentle.
I have an iOS 5 app (using storyboards) where I want the user to have the ability to sign out, and with that reset all settings in the app, and also return the user to the very first nib view.
I have already used this code:
[self.navigationController popViewControllerAnimated:YES];
and the problem with this is that it only sends the user back 1 view and not several.
The issue with this is that I have multiple table views that derive from each other and I want the Sign Out button to remain visible in every single one of these detailed views.
Also, this has to work on both iPhone and iPad (Universal)
Any suggestions?
Thanx.
Why not assign a BOOL value YES on button click, then in the viewWillAppear of each viewController:
(assuming BOOL signingOut)
if(signingOut){ [self.navigationController popViewControllerAnimated:YES]; }
Otherwise, just use:
[self.navigationController popToRootViewControllerAnimated:NO];
Why not set the viewControllers array on the navigation controller.
Or send your logout command to the root controller of the navigation controller and have it pop the navigation controller without animation until there are two left. Then pop the second to last one animated. Then you should still get the navigation animation
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...:)
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.
I have been trying to figure this out for about a hour and can't seem to find the answer. So basically my app starts, and loads a new view, this view has a tabeview, i understand tableviews, but not navigation controllers as much.
I want this navigation controller to only be loaded with this new view, I don't need it throughout the new app.
I know you can use the app delegate, but I'm still confused if this would work with what I'm trying to accomplish.
If someone could either show me an article about this or just give me some code, that would be amazing.
Thanks very much
You can use navigation controller as the root view controller of your app and hide its navigation bar inside views that don't need it.
[self.navigationController setNavigationBarHidden:YES animated:YES];
To show it again, just call the same method with first parameter set to NO.
I am implementing a shopping cart in iOS.
I am using a UINavigationController to show UIViewControllers for each step of the process. Users can use the back button and change things.
But after they submit the order I don’t want them to go back. What is the correct way to show a view without the back button using the navigation controller?
When you do that, what happen to the previous UIViewControllers? Are they deallocated ? Obviously I don’t need them. Do I have to manually deallocate them?
You have to deallocate those view controllers. They will start to leak, otherwise. I guess, you would be pushing the view controllers somehow similar to the following.
MyViewController *myViewController = [[MyViewController alloc] init];
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];
If you are doing like this, you have no need to worry about those view controllers, later. They will be released by the UINavigationController when it is done them.
Hiding the back button: Add the following line in the loadView method of your last view controller.
[self.navigationItem setHidesBackButton:YES];
You can tell it to go to a specific view controller either with something like:
[myNavController popToRootViewControllerAnimated:YES];
Or, there's also a UINavigationController method to give it an array of view controllers, it should present the first one.