UIWebView canGoBack和canGoForward总是返回NO [英] UIWebView canGoBack and canGoForward always return NO

查看:2047
本文介绍了UIWebView canGoBack和canGoForward总是返回NO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图直接加载数据到 UIWebView

I am trying to load data directly into UIWebView:

[webView loadData:data MIMEType:@"text/html" textEncodingName:@"utf-8" 
          baseURL:nil];

数据是一些包含一些外部链接的html字符串。我试图在 UIWebView 属性上启用后退和前进按钮:

The data is some html string contains some external links. I am trying to enable the back and forward buttons base on the UIWebView properties:

self.forwardBtn.enabled = self.webView.canGoForward;
self.backBtn.enabled = self.webView.canGoBack;
However, even after I clicked on different links in the web view after the initial load, the webView.canGoForward and webView.canGoBack are always returning NO.
Any idea about this?

推荐答案

是如果我使用loadData或loadHTMLString,然后检查在委托的请求的URL:

Ok, I think the problem is if I use loadData or loadHTMLString, and then I check the url of the request in the delegate:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSLog(@"url=%@", [request URL]);
    return YES;
}

看起来url是空的。
我认为这是为什么使用loadData时没有goBack的历史。

It seems like that url is empty. I think this is why there is no history for goBack when using loadData.

这篇关于UIWebView canGoBack和canGoForward总是返回NO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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