4

I would like to know how I can add a back button to my UINavigationBar, I know that If I embed in a Navigation Controller in my main view, that all of this would happen automatically, but that is not what I am trying to do, in fact, the back button could go to any other view I connect the segue to, doesn't even have to be the back.

The back button needs to be the system navigation "back" button, I don't want to have to set image files for my buttons.

I tried dragging in a bar button item in storyboard but nothing shows up, doesn't seem to be doing the trick. The navigation bar was dragged to the view in storyboard (not created programmatically) and it shows up just fine.

I looked at the following similarly asked questions:

-> How do i add a 'back' button to a UINavigationBar manually?

-> How to add a button to UINavigationBar?

-> How to programmatically add a UINavigationBar and a back button on it

but they all point to just embedding the view in a navigation controller, which again, is not what I am trying to do.

If someone can please help me out, provide some sample code I would greatly appreciate it.

Community
  • 1
  • 1
vzm
  • 2,440
  • 6
  • 28
  • 47
  • A relevant question to ask yourself is why? Why are trying to do something that works contrary to the standard UI, and something that people are familiar with? if you need to provide a custom navigation element, then use the `rightBarButtonItem` to do so, that's what it was intended for. The left side of a navigation controller should always be used to navigate up the view hierarchy. – Ric Perrott Jul 19 '13 at 15:32
  • 1
    If you dont push your viewController, the backButton you set in interfaceBuilder will be nil, and therefor will not be presented. The best solution is really to set a UIBarButton to self.navigationItem.leftBarButton or self.navigationItem.backBarButtonItem. finding images for that button is easy. search the web – Lirik Jul 19 '13 at 15:33
  • I second what @RicPerrott said. The back button should ONLY go to the previous view controller in a navigation stack. What you're trying to do will probably get you rejected by the app store (and even if you're not going through the app store, this is just bad UI design). – rdelmar Jul 19 '13 at 15:55

1 Answers1

2

Try drag-drop a UIButton object. I have always added manual back button (hardly took the in-built one)

Jean
  • 2,611
  • 8
  • 35
  • 60