在swift中使用UIImageview获取错误GestureRecognizer

时间:2015-06-13 14:28:13

标签: ios iphone swift uiimageview uigesturerecognizer

我正在使用20 uiimageview,所以我给出了每个imageview的标签值

现在我想在每个图像视图上添加GestureRecognizer

for index in 0 ... fields.count - 1{


            let gestureRecognizer = UITapGestureRecognizer(target: self, action: "fieldsTappedAction")
            gestureRecognizer.numberOfTapsRequired = 1
            println(fields[index])
            fields[index].addGestureRecognizer(gestureRecognizer)


        }

现在我正在尝试使用fieldsTappedAction获取标记

 func fieldsTappedAction (recognizer:UITapGestureRecognizer){


        let tappedField = recognizer.view as! TTTImageView
        tappedField.setPlayer(currectPlayer)
}

但是当我录制的图像视图让应用程序在点按时崩溃时它无法正常工作。

fieldsTapped]: unrecognized selector sent to instance 0x7fc95a4abf90
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-

1 个答案:

答案 0 :(得分:2)

您的选择器有参数,因此在其名称后需要冒号。所以:

let gestureRecognizer = UITapGestureRecognizer(target: self, action: "fieldsTappedAction:")