iPhone - 如何让自定义浏览器能够检测是否需要启用/禁用后退/前进按钮

发布于 2024-11-01 20:11:15 字数 1050 浏览 0 评论 0原文

嘿伙计们!我正在开发一个 tumblr 应用程序,并且有一个按钮可以推送一个模态视图,其中包含一个 web 视图和底部的工具栏,其中包含刷新、后退、前进和完成按钮。后退和刷新按钮可以工作,但是我希望能够判断网络视图是否实际上可以后退/前进,如果不能,则禁用该按钮。我已经尝试了下面的代码,并且图像和启用/禁用更改。

- (IBAction)refreshPage {
    [signUpWebView reload];
}

- (IBAction)goBack {
    [signUpWebView goBack];
}

- (IBAction)goForward {
    [signUpWebView goForward];
}


-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    // Enable or disable back
    if ([signUpWebView canGoBack]) {
        [backOnePage setEnabled:YES];
        backOnePage.image = [UIImage imageNamed:@"backButton"];
    } else {
        [backOnePage setEnabled:NO];
        backOnePage.image = [UIImage imageNamed:@"backButtonDisabled"];
    }

    // Enable or disable forward
    if ([signUpWebView canGoForward]) {
        [forwardOnePage setEnabled:YES];
        forwardOnePage.image = [UIImage imageNamed:@"forwardButton"];
    } else {
        [forwardOnePage setEnabled:NO];
        forwardOnePage.image = [UIImage imageNamed:@"forwardButtonDisabled"];
    }

}

任何建议将不胜感激!

Hey guys! I have a tumblr app that I am developing, and I have a button that pushes a modal view that contains a webview and a toolbar on the bottom with refresh, back, forward and done buttons. The back forward and refresh buttons work, however I want to be able to tell if the webview can actually go back/forward and if not, disable the button..I have tried the code below, and the image nor the enable/disable changes.

- (IBAction)refreshPage {
    [signUpWebView reload];
}

- (IBAction)goBack {
    [signUpWebView goBack];
}

- (IBAction)goForward {
    [signUpWebView goForward];
}


-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    // Enable or disable back
    if ([signUpWebView canGoBack]) {
        [backOnePage setEnabled:YES];
        backOnePage.image = [UIImage imageNamed:@"backButton"];
    } else {
        [backOnePage setEnabled:NO];
        backOnePage.image = [UIImage imageNamed:@"backButtonDisabled"];
    }

    // Enable or disable forward
    if ([signUpWebView canGoForward]) {
        [forwardOnePage setEnabled:YES];
        forwardOnePage.image = [UIImage imageNamed:@"forwardButton"];
    } else {
        [forwardOnePage setEnabled:NO];
        forwardOnePage.image = [UIImage imageNamed:@"forwardButtonDisabled"];
    }

}

Any recommendations would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

万劫不复 2024-11-08 20:11:15

我建议将前进和后退按钮直接绑定到 UIWebview。

在此处输入图像描述

自动启用和禁用,如下所示:

- (void)webViewDidStartLoad:(UIWebView *)mwebView {
    backButton.enabled = (webView.canGoBack);
    forwardButton.enabled = (webView.canGoForward);
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    backButton.enabled = (webView.canGoBack);
    forwardButton.enabled = (webView.canGoForward);
}

I recommend binding the forward and backward button directly to the UIWebview.

enter image description here

Automatically enable and disable like this:

- (void)webViewDidStartLoad:(UIWebView *)mwebView {
    backButton.enabled = (webView.canGoBack);
    forwardButton.enabled = (webView.canGoForward);
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    backButton.enabled = (webView.canGoBack);
    forwardButton.enabled = (webView.canGoForward);
}
情独悲 2024-11-08 20:11:15

当您首次初始化 webView 时,请尝试使用请求启动它,如下所示:

[signUpWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];

因此,您将使用 loadRequest: 而不是 loadHTMLString: 来初始化 webView代码>,或类似的东西。

When you first initialize your webView, try starting it with a request, like this:

[signUpWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];

So you're initializing the webView with loadRequest: instead of loadHTMLString:, or something similar.

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