每当访问特定页面时都会重新加载该页面?
我试图找出在 xcode 中使用后退按钮时重新加载特定页面的最佳方法。这就是我现在所拥有的
-(IBAction)backButton {
[webView goBack];
[webView reload];
}
,我想要发生的事情是,我不想在点击后退按钮时刷新每个页面,我只希望刷新我的本地 html,所以像
-(IBAction)backButton {
[webView goBack];
if ("url matches localHTML"){
[webView reload];
}
}
我想要刷新的 localHTML 只是主页。我知道解决方案不会像上面那么简单,但我只是想向您展示我正在寻找的内容。感谢您的帮助。
I am trying to figure out the best way to reload a specific page when using the back button in xcode. Here is what I have right now
-(IBAction)backButton {
[webView goBack];
[webView reload];
}
All I want to have happen, is instead of refreshing every page when tapping the back button, I only want my local html to be refreshed, so something like
-(IBAction)backButton {
[webView goBack];
if ("url matches localHTML"){
[webView reload];
}
}
The localHTML that I want refreshed is only the homepage. I know the solution wouldn't be as simple as above, but I'm just trying to show you what I'm looking for. Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您检查过委托方法 [UIWebViewDelegate webView:shouldStartLoadWithRequest:navigationType:] 吗?
如果请求中的 URL 与您想要允许的 URL 不匹配,您似乎可以返回 NO(即不加载)。
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIWebViewDelegate/webView:shouldStartLoadWithRequest:navigationType< /a>:
如果您只想刷新本地 HTML,请执行以下操作:
如果您还使用不同的域,您可以使用并围绕我在那里编写的代码片段,以允许从该域进行初始提取。
Have you checked out the delegate method [UIWebViewDelegate webView: shouldStartLoadWithRequest: navigationType:]?
Seems like you could return NO (i.e. don't load) if the URL in the request doesn't match one you want to allow.
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIWebViewDelegate/webView:shouldStartLoadWithRequest:navigationType:
And if you want to only refresh the local HTML, do something like:
And if you're also working with a different domain, you can probably work with and around the code snippet I've written up there to permit initial fetches from that domain.