在iOS中加载HTML后,UIWebView不会返回 [英] UIWebView won't goBack after loading HTML in iOS

查看:428
本文介绍了在iOS中加载HTML后,UIWebView不会返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的iPhone应用程序中遇到此问题:我有一个首先加载HTML字符串的webView。在用户单击链接并加载请求的页面后,当我调用方法时,webView将不会返回 [UIWebView goBack]; 我认为webView不会缓存HTML字符串。有什么办法可以让webView缓存我的HTML字符串,而不必自己将它保存在NSString中吗?

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?

推荐答案

你可以使用canGoBack属性,如果你不能返回,请使用原始html重新加载UIWebView。如果用户使用链接向前导航,则canGoBack属性将返回YES,并且可以在UIWebView上启动goBack。 _htmlString是使用HTML字符串初始化UIWebView时设置的成员变量。 -rrh

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];
}

这篇关于在iOS中加载HTML后,UIWebView不会返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆