Search code examples
iosobjective-csprite-kituigesturerecognizerskview

SKView gestureRecognizer [UITapRecognizer name]: unrecognized selector sent to instance


-(void)didMoveToView:(SKView *)view
{
    UITapGestureRecognizer* doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];
    doubleTapGestureRecognizer.numberOfTapsRequired = 2;
    [self.view addGestureRecognizer:doubleTapGestureRecognizer];
}
-(void)doubleTap:(id)sender
{
    NSLog(@"double tap");
}

I am using this to add a gesture recognizer to my SKView. It works fine, double tap gets called when i double tap, but when i touch the screen and move my finger, app crashes with this error:

[UITapRecognizer name]: unrecognized selector sent to instance 0x1756c600

Why is this happenning? Im not calling any "name" selector on this recognizer.

I have this method:

#pragma mark - SKPhysicsContactDelegate

-(void)didBeginContact:(SKPhysicsContact *)contact
{
    if(![contact.bodyA.node.name isEqualToString:@"player"])
    {
        [contact.bodyA.node performSelector:@selector(removeFromParent) withObject:nil afterDelay:1];
    }
    if(![contact.bodyB.node.name isEqualToString:@"player"])
    {
        [contact.bodyB.node performSelector:@selector(removeFromParent) withObject:nil afterDelay:1];
    }

}

i noticed that if i comment this out, there is no such error, but then i replaced it with this:

-(void)didBeginContact:(SKPhysicsContact *)contact
{
    if(![contact.bodyA.node respondsToSelector:@selector(name)])
    {
        NSLog(@"%@ , %@ \n",contact.bodyA, contact.bodyA.node);
    }
    if(![contact.bodyB.node respondsToSelector:@selector(name)])
    {
        NSLog(@"%@ , %@",contact.bodyB, contact.bodyB.node);
    }
}

and there is nothing in debug log, just the same error. What is going on?


Solution

  • turned out is was a duplicate of -> UITapGestureRecognizer causes app to crash

    "I had the same issue in one of my SpriteKit Games, it is caused when you use gestures during transition between scenes, i solved it by setting gestureRecognizer.enable property (documentation) to NO before the transition." That answer helped