iOS uiwebview goBack历史控制 [英] iOS uiwebview goBack history control

查看:1744
本文介绍了iOS uiwebview goBack历史控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在uiwebview上加载webpage1并将其第一个请求保存在实例变量webviewHistory上。然后,我必须重用该webview加载另一个页面webpage2(也保存其第一个请求到webviewHistory),历史应该从这个请求开始。问题是如果我从webpage2执行goBack(按钮IBAction),我可以继续回到webpage1历史记录和以下。
如果我检查请求并与初始保存的比较,工作!但不能重定向,例如,如果我触发请求到www.youtube.com,请求重定向到m.youtube.com,第一个不保存为导航历史!如何解决呢?

I am loading a "webpage1" on an uiwebview and saving its first request on an instance variable "webviewHistory". Then, I must reuse that webview to load another page, "webpage2" (saved its first request to "webviewHistory" too), and history should start now from this request. Problem is if I execute goBack (button IBAction) from "webpage2", I can keep going back to "webpage1" history and following. If I check request and compare with initial saved, works! but not with redirections, for example, if I trigger request to www.youtube.com, request is redirectioned to m.youtube.com and first one is not saved as navigation history! how to solve it?

if (![webViewSocial.request.URL.absoluteString isEqualToString:self.webviewHistory]){
    [webViewSocial goBack];
    }


推荐答案

UIWebviews有实例方法您可以随着历史记录前后移动,而无需跟踪最后一个请求。

UIWebviews have instance methods that allow you to go backwards and forwards with the history, without you having to track the last request. Is there a particular reason you are saving the last request specifically?

示例代码:

if ([webView canGoBack]) {
    [webView goBack];
}

这里是一个项目,它是一个简单的uiwebview浏览器,如果你想玩it:
https://github.com/msencenb/UIWebView-Example

Here is a project that is a simple uiwebview browser if you want to play with it: https://github.com/msencenb/UIWebView-Example

这篇关于iOS uiwebview goBack历史控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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