Reputation: 6823
Is there anyway to tell what specifically the back button from a navigation controller does? I know in terms of what it does, but in terms of method called/functions etc.
The reason is that I am hiding the navigation bar and will have a button on view instead and just want to replicate this completely.
Upvotes: 1
Views: 300
Reputation: 13549
If the you're referring to the leftBarButtonItem and not the built in backButton, then it can do whatever you want. It does not automatically dismiss the current view controller. You need to hook up a selector to the barButtonItem for it to do anything. When that action is fired, you tell it what to do whether it be pop, segue, or virtually anything.
Upvotes: 0
Reputation: 31745
This is the UINavigationController method that the back button calls:
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
So to replicate it just do something like this in the viewController you are popping...
[self.navigationController popViewControllerAnimated:YES];
You can verify that this is exactly the method called by the back button by subclassing UINavigationController and overriding this method - you will see that it gets called when the back button is pressed (no need to do this in your app - it's just a way for you see what is going on!)
Upvotes: 0
Reputation: 5405
In your view controller call this, when your custom back button is tapped:
[self.navigationController popViewControllerAnimated:YES];
This will pop the current view controller.
Upvotes: 2
Reputation: 23278
If you want to replicate the back button feature in navigation bar, you need to call the following in that button's action:
[self.navigationController popViewControllerAnimated:YES]
Upvotes: 4