Back Button on UIWebView(UIWebView 上的后退按钮)
问题描述
我试图弄清楚如何创建一个允许用户返回一页的后退按钮.我通读了 Apple 的 Docs(它仍然超出我的想象),发现我需要设置 canGoBack
和 goBack
的.我已经尝试过了,但由于某种原因它不起作用.我的 UIWebView
被命名为 viewWeb
,我创建了一个插座并将其附加到我的后退按钮上,命名为 backButton
,并将其标记为 1.这里是我在 View Controller 中编写的代码:
I'm trying to figure out how to create a back button that allows the user to go back one page. I read through Apple's Docs (which still go way over my head) and found out that I need to setup the canGoBack
and goBack
's. I have tried this, but for some reason it is not working. My UIWebView
is named viewWeb
, and I created and attached an outlet to my Back button, named backButton
, and also tagged it as 1. Here is my code that I wrote in the View Controller:
// Back button:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[_backButton addTarget:_viewWeb
action:@selector(goBack)
forControlEvents:UIControlEventTouchDown];
if ([_viewWeb canGoBack]) {
NSLog(@"Back button pressed.");
[_viewWeb goBack];
}
}
else return;
}
有人知道我需要更改/添加什么才能使其正常工作吗?
Does anyone know what I need to change / add to get this working?
推荐答案
actionSheet:clickedButtonAtIndex:
适用于 UIActionSheet
对象,而非 UIButton
动作.
actionSheet:clickedButtonAtIndex:
is for UIActionSheet
objects, not UIButton
actions.
您可能应该编写一个如下所示的 IBAction
方法:
You should probably write an IBAction
method that looks something like this:
- (IBAction)backButtonTapped:(id)sender {
[_viewWeb goBack];
}
并将其连接到按钮的 Touch Up Inside 操作.
and connect it to the Touch Up Inside action from the button.
您可以在 IBAction
上搜索更多信息,但这可能正是您想要的
You can search for more info on IBAction
but that's likely what you want
这篇关于UIWebView 上的后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIWebView 上的后退按钮


基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01