I have a storyboard with a UIViewController with some buttons. One of the buttons does a modal segue to a UINavigationController and the NavController has a UITableViewController embedded in it. When I click the button on the home screen it advances to the NavController but there is not back button.
So how do I get a back button? I have tried a few things, but no luck.
Thanks for the help!!
If you are presenting the navigation controller modally, then the tableview controller is the only view controller your new navigation controller has pushed. There would not be and should not be a back button in that case.
You'd be better off adding a cancel/done button to the nav bar via the tableview controller, which dismisses the modal view.
In your tableView controller viewDidLoad: method:
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonTapped:)];
self.navigationItem.leftBarButtonItem = done;
//Release done if not using ARC
Then add (the simplest implementation of) a dismiss method:
- (void)doneButtonTapped:(id)sender {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
A UINavigationViewController only manages a stack of view controllers. You push a viewController onto the stack, and when you hit "back" you are popping a view off of the stack.
Since you are presenting the UINavigationController modally, it has no knowledge of what was presented before it. The correct way to get the desired behavior is to set your main UIViewController to the UINavigationController's root view controller. When the user taps a button, you push the new UITableViewController onto the UINavigationController's stack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With