Back UIButton Controlling UINavigationController - iphone

I have looked everywhere for this.
I have a navigation controller. I like using the navigation controller with all the animation however the bar irritates me so i have disabled it.
I would like to create a UIButton that will push the navigation controller back a page instead.
Is this possible? can someone tell me how to achieve this and get hold of the correct item that allows to push back to the previous view.
Thanks

Create a button with a target on a function that do:
[self.navigationController popViewControllerAnimated:YES]
Since navigation controller works as a stack your current view controller is poped out from the stack and the previous view controller is showed

Look at the UINavigationController documentation, you can have your UIButton call the navigation controller's popViewControllerAnimated:

Did you try these methods in the UINavigationController class:
– pushViewController:animated:
– popViewControllerAnimated:
– popToRootViewControllerAnimated:
– popToViewController:animate
Call the pop methods from your button's action method.

Assuming you have a valid reference to the Nav Controller, set up the button action to use:
Pops view controllers until the specified view controller is at the top of the navigation stack.
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated

Related

Quickly returning to RootViewController

Is there any way to quickly go to rootViewController? I want to remove all views from the stack & return to rootViewController without even bothering the sequence of views on top of it.
From the docs:
popToRootViewControllerAnimated:
Pops all the view controllers on the stack except the root view controller >and updates the display.
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
Parameters
animated:
Set this value to YES to animate the transition. Pass NO if you are setting >up a navigation controller before its view is displayed.
Return Value:
An array of view controllers that are popped from the stack.
First I think you need to dismiss presented model then you can pop all the pushed view controllers. As presented model would not be in the stack of the navigation.
[self dismissModalViewControllerAnimated:YES];
Then you can pop to base view controller.
[self.navigationController popToRootViewController:YES];
Try this:-
[self.viewController popToRootViewController:YES];

popToRootViewControllerAnimated doesn't modify attached navigationItem

My UIViewController calls a function on my rootViewController which then called popToRootViewControllerAnimated to return the view to the rootController. This all works - great!
Unfortunately the UINavigationItem (toolbar at the top) seems to display a mashup of both the rootViewController and the UIViewController that has just been removed.
What do I need to do? What have I done wrong?
The navigation bar doesn't remember changes that were made to it, so when you push a new controller, the navigation bar is altered to give the title of the new view controller, but it doesn't store what was there for the previous view controller.
You will need to recreate the items in the toolbar each time you come back to the view controller that has custom items.
You might be able to do this on viewWillAppear instead of viewDidLoad. I can't recall exactly, but you should recreate custom controls on navigation toolbar because it does not get preserved when a new view controller is pushed.
It seems that calling popToRootViewController from the rootViewController messes things up. TO rectify this I called the following from within the calling UIViewController
[self.navigationController popViewControllerAnimated:YES];

Navigation application -- Back Button

When we click on the back button on a nav view, is there any method (delegate) which gets called on current view controller before poping it out of stack and pushing next in stack?
The only method available is the viewWillDisappear and the viewDidDisappear in the viewController managed by the UINavigationController. You might be able to check the size of the UINavigationController viewController array property and compare it with the last known -count. If there are more controllers in the stack, you know that something was pushed. If there are less, something was popped.
You can hook up your own -back:(id)sender method as the selector for your back button and then do what ever you want inside that method, as long as you call:
[[self navigationController] popViewControllerAnimated:YES];

UINavigationController return to first view

I am using a UINavigationController to slide from a UITableViewController to another view. In that second view I have created a custom "Back" button which is attached to an action.
What code do I use to return to dismiss the current view and slide back to my first view? I need something that is the equivalent to [super dismissModalViewControllerAnimated:true]; but obviously this is not a modal view.
Thanks.
Look at one of the following three methods on your navigation controller:
popViewControllerAnimated:
popToRootViewControllerAnimated:
popToViewController:animated:
Depending on how you want to handle it of course. Generally one just uses the first method to go back to the last view (the one that pushed your current view onto the navigation stack).
Use popToRootViewControllerAnimated method in UINavigationController:
[self.navigationController popToRootViewControllerAnimated:animated];

how to pop a controller off the navigation stack without using the navigation bar

I'm trying to implement a navigation controller with some hierarchical views. I want to use a regular UIViewController to present choices for drilling down, I don't want to use the navigation bar - I want to have my own, custom buttons for returning back up a level.
I see examples like:
[[self navigationController] pushViewController:nextViewController animated:YES];
and my questions are these: Is navigationController a property of all UIViewControllers? Can I refer to self.navigationController regardless of the view that's on the stack? If I'm at an arbitrary view, can I have a button action that contains something like [self.navigationController popToRootViewController animated:YES];
Each view I present will need a button to return to the previous view, or to the root view, depending on the situation. I want to create that button in each view controller and control which view in the stack it returns to. Am I on the right track?
Is navigationController a property of all UIViewControllers?
Yes.
Can I refer to self.navigationController regardless of the view that's on the stack?
Every UIViewController on the UINavigationController's stack will return the UINavigationController object when calling navigationController on it.
If I'm at an arbitrary view, can I have a button action that contains something like [self.navigationController popToRootViewControllerAnimated:YES];
Yes. popToRootViewControllerAnimated: will take the user to the root UIViewController for the UINavigationController, and you can use [self.navigationController popViewControllerAnimated:YES]; to just pop off the top UIViewController. This last one does the same as tapping the Back UIBarButtonItem.
Am I on the right track?
Yes :)