Ios 手势

Ios 手势,ios,swift,Ios,Swift,我正在试验轻拍手势 我试图向视图中添加点击手势,但当点击发生时,我得到一个错误 这是我的密码: class ViewController: UIViewController { @IBOutlet weak var myView: UIView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a

我正在试验轻拍手势

我试图向视图中添加点击手势,但当点击发生时,我得到一个错误

这是我的密码:

class ViewController: UIViewController {

@IBOutlet weak var myView: UIView!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    myView.backgroundColor = UIColor.redColor()

    let tapGestureRecognizer:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "TapPageHandler")

    myView.addGestureRecognizer(tapGestureRecognizer)
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


func TapPageHandler(recognizer: UITapGestureRecognizer){

    print("hello world")
}
}
我得到的错误是:

2016-05-14 20:08:47.753 TapGestureTest[6641:245475]-[TapGestureTest.ViewController TapAgeHandler]:发送到实例0x7fc1fb58f430的无法识别的选择器 2016-05-14 20:08:47.813 TapGestureTest[6641:245475]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[TapGestureTest.ViewController TapAgeHandler]:


有人能指导我完成这件事吗?并告诉为什么会发生这种情况?

您有不同的选择器签名和方法签名(您的方法签名需要一个参数,而选择器签名需要一个没有参数的方法)

您需要指定选择器,如:

let tapGestureRecognizer:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "TapPageHandler:")

您有不同的选择器签名和方法签名(方法签名需要一个参数,选择器签名需要一个没有参数的方法)

您需要指定选择器,如:

let tapGestureRecognizer:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "TapPageHandler:")
action:“TapPageHandler”应该是action:“TapPageHandler:”,则:定义它将需要一个参数。

action:“TapPageHandler”应该是action:“TapPageHandler:”,则:定义它将需要一个参数