0

I've a WebviewViewController and a navigation bar with the Back Bar Button. Now I want two buttons on the right of the bar, a goBack and a goForward. I've searching for a while and none of the answers works properly.

There's a way to add them in the storyboard or only programmatically? If so, how do I do it?

Popeye
  • 11,839
  • 9
  • 58
  • 91
MADPT
  • 97
  • 2
  • 12

1 Answers1

2

I did it in the past, it's easy:

myBackBarButton = [[UIBarButtonItem alloc] initWithImage:barButtonImage
                                           style:UIBarButtonItemStylePlain
                                           target:myWebView
                                           action:@selector(goBack)];

myForwardButtom = [[UIBarButtonItem alloc] initWithImage:anotherBarButtonImage
                                           style:UIBarButtonItemStylePlain
                                           target:myWebView
                                           action:@selector(goForward)];

Where myWebView is your UIWebView (In case it's your class, use self)

If your buttons are already created, then just add the target and the action to them:

myBackButton.target = myWebView;
myBackButton.action = @selector(goBack);

What you are doing is adding the action goForward: and goBack: of the target that is your webview, to those buttons.

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
  • An warning appears in the selector goBack "undeclared selector 'goBack' " and the same for the goForward. If I remove the :, the warning disappears. However the buttons still don't appear in the nav bar. – MADPT Oct 16 '13 at 12:18
  • But how can I add those two buttons on the right of the nav bar? – MADPT Oct 16 '13 at 12:27
  • 1
    Here you have: http://stackoverflow.com/questions/1803609/how-to-add-2-buttons-into-the-uinavigationbar-on-the-right-side-without-ib – Antonio MG Oct 16 '13 at 12:28