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.