UITapGestureRecognizer无法识别的选择器发送到实例 [英] UITapGestureRecognizer unrecognized selector sent to instance

查看:158
本文介绍了UITapGestureRecognizer无法识别的选择器发送到实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了这个问题的解决方案,但在我的案例中找不到任何似乎可以解决它的问题。我从UITapGestureRecognizer获得了上述异常。

I've searched for solutions to this problem but couldn't find anything that seems to address it in my case. I'm getting the above exception from a UITapGestureRecognizer.

以下是简化代码:

import UIKit;

class ViewController : UIViewController, UIScrollViewDelegate
{
    @IBOutlet weak var scrollView:UIScrollView!;
    var imageView:UIImageView!;

    override func viewDidLoad()
    {
        super.viewDidLoad();

        ... set up imageView/scrollView here ...

        let doubleTapRecognizer = UITapGestureRecognizer(target: self, action: "onScrollViewDoubleTapped");
        doubleTapRecognizer.numberOfTapsRequired = 2;
        doubleTapRecognizer.numberOfTouchesRequired = 1;
        scrollView.addGestureRecognizer(doubleTapRecognizer);
    }


    func onScrollViewDoubleTapped(recognizer:UITapGestureRecognizer)
    {
    }
}

有人能说出这段代码有什么问题吗?这对我来说似乎都是正确的。我怀疑它与将ViewController指定为scrollView的委托(反之亦然)有关?但是,ViewController被设置为scrollView的委托。但也许是其他导致此错误的东西?

Can anyone tell what is wrong with this code? It seems all correct to me. I suspect that it has to do with assigning ViewController as delegate to scrollView (or vice versa)? However the ViewController is set as the delegate to scrollView. But maybe it's something else that causes this error?

推荐答案

尝试在选择器字符串中添加冒号。

Try adding a colon to your selector string.

let doubleTapRecognizer = UITapGestureRecognizer(target: self, action: "onScrollViewDoubleTapped:");

正如cabellicar123所提到的,这表明选择器接受了一个参数。

As cabellicar123 mentioned, this indicates that the selector takes an argument.

这篇关于UITapGestureRecognizer无法识别的选择器发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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