getting error GestureRecognizer with UIImageview in swift

195 views Asked by At

i am using 20 uiimageview so i have given tag value of each imageview

now i want to add GestureRecognizer on each image view

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


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


        }

now i am trying to get tag using fieldsTappedAction

 func fieldsTappedAction (recognizer:UITapGestureRecognizer){


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

but its not working when i taped imageview getting app crashed in the time of tap.

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

There are 1 answers

0
Ali Beadle On BEST ANSWER

Your selector has arguments so needs a colon after its name. So:

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