0

In my app I would like to have a way to make the user go to a website, but not leave my app.
I do that with a UIWebView.
I'd like to constantly have a "Back to app" button on the NavigationBar on the top.
The rest of the Web navigation (back, forward) should be on the top as well, but appear and disappear with the context.

The problem is that I don't know how to make the buttons appear on the UINavigationController. How can this be done?

I have my UIWebViewDelegate set up to receive all the relevant functions, but the buttons don't appear.

EDIT: I need to solve this programmatically

Ted
  • 3,805
  • 14
  • 56
  • 98
  • Is the problem that's you can't see the UINavigationBar? – Martol1ni Nov 04 '12 at 13:05
  • Are you pushing a new ViewController with the webview, or just adding it as a subview in your presented ViewController? – Martol1ni Nov 04 '12 at 13:07
  • Funny, I am trying to demystify the issue in Interface Builder, I can't even place more than a left and a right button on the navigationBar. Is placing more than two buttons even possible? – Ted Nov 04 '12 at 13:10

2 Answers2

1

As of iOS 5, there are leftBarButtonItems and rightBarButtonItems (note the plural) properties on UINavigationItem, so there's a way to have more buttons. It seems to me that these are only accessible programmatically, but not from Interface Builder.

If you can, my suggestion is to not just add the Web View as a subview, but to give it its own ViewController and push that on the Navigation Controller's stack. That'll give you your back button for free (that's kind of what UINavigationController was designed for, after all). And it should help you to keep the web browsing code separated form the other stuff in your app.

NB: in your case, you'll have set the leftItemsSupplementBackButton property of the Browser View Controller's navigationItem to YES to get the automatic back button (the details are in the documentation)

Jörn Eyrich
  • 5,141
  • 1
  • 19
  • 14
  • My app supports iOS 4, but really good points to look at. Thanks for your eye opening answer :) – Ted Nov 04 '12 at 15:24
0

You can not have more than two buttons on the NavigationController's navbar without doing some tricks. There are two properties self.navigationItem.leftBarButtonItem and self.navigationItem.rightBarButtonItem. If not, add a custom view and place the buttons there. A good way to implement multiple buttons with multiple actions is shown here.

Community
  • 1
  • 1
Martol1ni
  • 4,684
  • 2
  • 29
  • 39
  • As of iOS 5.0, this answer is not correct. `UINavigationItem` has `leftBarButtonItems` and `rightBarButtonItems` properties. – rmaddy Nov 04 '12 at 15:42