Pop Flamingo
Pop Flamingo

Reputation: 2191

Pan gesture recognizer selector won't work

In a SpriteKit game, I am trying to create a UIPanGestureRecognizer without using Interface Builder, so in the didMoveToView method of my SKScene, I wrote this :

let panGestureRecogniser = UIPanGestureRecognizer(target: view, action: "didPan:")
view.addGestureRecognizer(panGestureRecogniser)  

Still in my SKScene class, I wrote this function :

func didPan(sender:UIGestureRecognizer) {
        println("Panned")
    }

My issue is that when I run my app, and when I pan on the screen, this error in thrown :

2015-05-12 19:28:01.955 Game[7342:2394353] -[SKView didPan:]: unrecognized selector sent to instance 0x154520690

I don't understand what's wrong, I have tried to move the function in both my view controller and app delegate, but it doesn't seem to make any difference...

Upvotes: 1

Views: 1327

Answers (1)

Fawad Masud
Fawad Masud

Reputation: 12344

Change

let panGestureRecogniser = UIPanGestureRecognizer(target: view, action: "didPan:")

To

let panGestureRecogniser = UIPanGestureRecognizer(target: self, action: "didPan:")

Upvotes: 5

Related Questions