iPhone - 如何让自定义浏览器能够检测是否需要启用/禁用后退/前进按钮
嘿伙计们!我正在开发一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议将前进和后退按钮直接绑定到 UIWebview。
自动启用和禁用,如下所示:
I recommend binding the forward and backward button directly to the UIWebview.
Automatically enable and disable like this:
当您首次初始化 webView 时,请尝试使用请求启动它,如下所示:
因此,您将使用
loadRequest:
而不是loadHTMLString:
来初始化webView
代码>,或类似的东西。When you first initialize your webView, try starting it with a request, like this:
So you're initializing the
webView
withloadRequest:
instead ofloadHTMLString:
, or something similar.