DemetriP
DemetriP

Reputation: 1

TapGestureRecognizer not calling selector

So I have a custom view that I am creating many of in a for-loop in my viewcontroller. While they're being created, I'm calling this method on each of them:

-(void)setUpStuff{
    //Random setup code
    [self setUserInteractionEnabled:YES];
    tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self   action:@selector(tileSelected:)];
    tapGesture.numberOfTapsRequired = 1;
    tapGesture.numberOfTouchesRequired = 1;
    [self addGestureRecognizer:tapGesture];
}

And this is the selector it should be calling:

-(void)tileSelected{
    NSLog(@"Why am I not working?");
    [self.delegate tileSelected:self];
}

It's probably worth mentioning that this customView has an imageView and label embedded within it. I've tried adding the gesture recognizer to the imageView and making sure that the imageView is being brought to the very front, however, that doesn't work either.. Any ideas?

Upvotes: 0

Views: 319

Answers (3)

wj2061
wj2061

Reputation: 6885

you can change your tileSelected func to :`

-(void)tileSelected:(UITapGestureRecognizer*)gesture{
    NSLog(@"Why am I not working?");
   [self.delegate tileSelected:self];
}

Upvotes: 0

Abhishek
Abhishek

Reputation: 509

Firts of all you need to set the view's user interaction enable on which you adding gesture and also your selector is including : at end of method that means you need to add parameter in method or just remove : from end of your selector.

Upvotes: 0

Leonardo
Leonardo

Reputation: 1750

Your selector call is wrong

it should be:

tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self   action:@selector(tileSelected)];

without the :

Upvotes: 1

Related Questions