1

I have a UITableViewController as the root view controller of a UINavigationController.

When the app launches, there is no back bar button on the navigation bar. However, when I click on one of the table view cells, and then click back, a back bar button appears at the top of the original UITableViewController. I don't want this. How can I get rid of this?

JRG-Developer
  • 12,454
  • 8
  • 55
  • 81
user1657563
  • 237
  • 4
  • 13
  • Since the back button is managed by the UINavigationController, there must be something to go back to. I'm curious what happens when you tap the back button? You must be pushing something else onto the navigation stack. – hukir Oct 31 '13 at 05:08

2 Answers2

1

On any view controllers that you don't want the back button to show, you can add this to the viewDidLoad method:

[self.navigationItem setHidesBackButton:YES animated:NO];

Alternatively, you can add this call in viewWillAppear:(BOOL)animated: if you want the change to be animated:

[self.navigationItem setHidesBackButton:YES animated:animated];
JRG-Developer
  • 12,454
  • 8
  • 55
  • 81
0

When your application opens up, the UITableViewController doesn't show a Back button because there is nothing to go back to. That's the Initial View Controller.

As for the second UIViewController that pushes on top of the previous UITableViewController - if you don't want the Back button in that - use a Modal transfer and not a Push transfer.

Apple's Navigation Controller simply functions like that. It works like a stack. One UIViewController gets pushed on the current one.

However, if you still want a Navigation Bar on top of the Modal segue UIViewController you can manually add it in the Interface Builder :

enter image description here

And then you can add a UIBarButton to the Navigation Bar.

But if you are still adamant on simply hiding the Back button, then use this method :

Put this in the viewDidLoad method of your UIViewController class's implementation :

[self.viewController setHidesBackButton:YES animated:NO];
Sam Fischer
  • 1,442
  • 19
  • 35
  • Right, I get that. I tried a modal transfer, but then the nav bar totally disappears which I also don't want. I just want the original Nav bar (which had an add button on the right side) without a new back button, if possible. – user1657563 Oct 31 '13 at 03:39
  • FYI - This will be a wrong approach if you want to `segue` from this `UIViewController` because it is a `Modal` segue. – Sam Fischer Oct 31 '13 at 03:47
  • Changing that setting in IB only changes the way IB renders it for you, it doesn't actually add the nav bar - that appears if and only if you are in a navigation controller and haven't hidden the bar. – Kevin Oct 31 '13 at 04:05
  • ...and that is why you should scroll down to the bottom of my answer. – Sam Fischer Oct 31 '13 at 04:06