7

I am trying to make a back button in my navigation bar because i already have a tab bar at the bottom of the screen.

my layout is this:

tab bar[
navigation bar {
webview ()
}
]

essentially. i need to programmatically add a back button and cannot seem to figure out how. i know that there is a goBack method but am not very familiar with how to implement this.

I already have a button which pulls up ana action sheet with several options but how would i go about having that use the goBack method?

as I understand I can also use something like

if (mywebview canGoBack) {
    [mywebview goBack]
}

but I'm not sure how to make an action sheet button do this.

any help?

Atulkumar V. Jain
  • 5,102
  • 9
  • 44
  • 61
begna112
  • 399
  • 2
  • 6
  • 14

1 Answers1

18

Somewhere in your action sheet's delegate file, you should have a method similar to this:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {      // if the first option is selected, whatever it may be... (counting starts at zero))
        if ([myWebView canGoBack]) {
            [myWebView goBack];
        }
    }

    else return;
}
esqew
  • 42,425
  • 27
  • 92
  • 132
  • ok well. apparently I cant do this because the webview cant go back from an actual webpage to a parsed rss feed. is there a way to have a navigation controller or webview simply go back to whatever was the last thing viewed? – begna112 Feb 21 '11 at 01:54
  • u can add a navigation controller, then use this question to proceed [link]http://stackoverflow.com/questions/1315587/setting-toolbar-items-of-uinavigationcontroller – Lior Frenkel Mar 30 '11 at 06:01
  • 1
    Small Change is needed: "if([webView canGoBack]) <---Added []'s – Nathan Mar 14 '12 at 14:26