xcode iOS init UIWebView 清除导航历史记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10963045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:32:53  来源:igfitidea点击:

iOS init UIWebView to clear navigation history

iphoneobjective-ciosxcodecocoa-touch

提问by Jaume

I am setting uiWebviewSocial as desired on IB and is loading requests as normal. However, later I need also to init this uiwebview in order to clear goBack history. I am using another uiwebview object for this purpose, webViewBridge

我正在根据需要在 IB 上设置 uiWebviewSocial,并且正在正常加载请求。但是,稍后我还需要初始化此 uiwebview 以清除 goBack 历史记录。为此,我正在使用另一个 uiwebview 对象 webViewBridge

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.webviewBridge = [[UIWebView alloc] init];
    self.webviewBridge = self.webViewSocial;

when I need to init UIWebViewSocial, I use following

当我需要初始化 UIWebViewSocial 时,我使用以下

    self.webViewSocial = nil;
    self.webViewSocial = [[UIWebView alloc] init];
    self.webViewSocial = self.webviewBridge;

however, if I then make goBack action, uiwebview loads an old request when should have its history empty. What I am missing? thank you

但是,如果我随后执行 goBack 操作,则 uiwebview 会在其历史记录为空时加载旧请求。我缺少什么?谢谢你

回答by isolMAC

Well, I've been going aroundUIWebViewin Stack Overflow these days and is a mess, for me at least.

好吧,UIWebView这些天我一直在 Stack Overflow四处走动,至少对我来说是一团糟。

It seemsUIWebViewcache works at its own, I mean we cannot change neither access some info that is exclusively managed by system...

UIWebView缓存似乎是独立工作的,我的意思是我们不能更改访问某些由系统专门管理的信息......

About your problem, it seems although yourUIWebViewis sent to nil, it keeps getting info from cache... so, you should clear cache firstable You can check it hereand there

关于你的问题,虽然你UIWebView被发送到 nil,但它不断从缓存中获取信息......所以,你应该先清除缓存你可以在这里那里检查

回答by Andy Obusek

The problem is that after you are init'ing the new webviewBridge or webviewSocial, you are immediately overwriting the new object with the assignment on the next line. Remove the third line in each method.

问题是在您初始化新的 webviewBridge 或 webviewSocial 之后,您会立即使用下一行的分配覆盖新对象。删除每个方法中的第三行。

回答by isolMAC

If I am not misunderstanding, when you load the view you get an "initial" webviewSocial (with history and contents??), then after some loadings you make in the UIWebView, these are stored as history in webviewBridge, isn't it? When you send webviewSocial to nil, that shall be empty... but NOT webviewBridge... and then if you are reloading webviewSocial with webviewBridge (which in fact is previous whole history), that's why it happens... I think

如果我没有误解,当您加载视图时,您会得到一个“初始”webviewSocial(带有历史记录和内容??),然后在您在 UIWebView 中进行一些加载后,这些将作为历史记录存储在 webviewBridge 中,不是吗?当你将 webviewSocial 发送到 nil 时,它应该是空的......但不是 webviewBridge......然后如果你用 webviewBridge 重新加载 webviewSocial(这实际上是以前的整个历史),这就是它发生的原因......我想

Saludos

萨卢多斯