每当访问特定页面时都会重新加载该页面?

发布于 2024-12-09 15:31:56 字数 400 浏览 1 评论 0原文

我试图找出在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴我老 2024-12-16 15:31:56

您检查过委托方法 [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,请执行以下操作:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL * urlWeAreConsidering = [request URL];
    if([urlWeAreConsidering isFileURL] == NO)
    { 
        // sends off a separate request
        [webView loadRequest: [NSURL URLWithString: @"file://LocalURL"]];
        return NO;
    }
    return YES;
}

如果您还使用不同的域,您可以使用并围绕我在那里编写的代码片段,以允许从该域进行初始提取。

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:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL * urlWeAreConsidering = [request URL];
    if([urlWeAreConsidering isFileURL] == NO)
    { 
        // sends off a separate request
        [webView loadRequest: [NSURL URLWithString: @"file://LocalURL"]];
        return NO;
    }
    return YES;
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文