UIWebView上的后退按钮 [英] Back Button on UIWebView

查看:173
本文介绍了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上的后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆