Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView won't goBack after loading HTML in iOS

I'm having this problem in my iPhone app: I have a webView which is first loaded with an HTML string. After the user clicks a link and it loads the requested page, the webView won't go back when I call the method [UIWebView goBack]; I suppose webView doesn't cache the HTML string. Is there any way I can make webView cache my HTML string without having to save it in a NSString myself?

like image 552
gabriel_vincent Avatar asked Jan 18 '12 03:01

gabriel_vincent


1 Answers

You can use the canGoBack property and if you can't go back, reload the UIWebView with the original html. If the user has navigated forward using links then the canGoBack property will return YES and a goBack can be initiated on the UIWebView. The _htmlString is a member variable that is set when the UIWebView is initialized using an HTML string. -rrh

- (void)goBack
{
    if (_htmlString && ![_browserWebView canGoBack]) {
        [_browserWebView loadHTMLString:_htmlString baseURL:nil];
        return;
    }
    [_browserWebView goBack];
}
like image 97
Richie Hyatt Avatar answered Nov 15 '22 00:11

Richie Hyatt