Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone UIWebView back button

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?

like image 689
begna112 Avatar asked Feb 20 '11 05:02

begna112


People also ask

What is UIWebView on Apple Iphone?

A view that embeds web content in your app.

Is UIWebView deprecated?

Apple is phasing out UIWebView, which is used by developers for integrating web content into an app in a quick and secure manner. Apple is replacing UIWebView (and WebView) with WKWebView, an updated version, as UIWebView has been deprecated.

What is the difference between UIWebView and WKWebView?

Unlike UIWebView, which does not support server authentication challenges, WKWebView does. In practical terms, this means that when using WKWebView, you can enter site credentials for password-protected websites.


1 Answers

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;
}
like image 148
esqew Avatar answered Sep 21 '22 12:09

esqew