Malloc
Malloc

Reputation: 16256

unrecognized selector sent to instance when click on UIImageView

I want to bind the tap event on a UIImageView like this:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self.backgroundImage action:@selector(imageClicked:)];
[self.backgroundImage addGestureRecognizer:tap];
self.backgroundImage.userInteractionEnabled=YES;

And the method is there:

-(void)imageClicked:(id)sender{

    NSLog(@"image clicked");
}

But when i click on the image view, my app crash and i got this stack:

[UIImageView imageClicked:]: unrecognized selector sent to instance 

Am i missing something? Thanx in advance.

Upvotes: 0

Views: 724

Answers (1)

Jacob Relkin
Jacob Relkin

Reputation: 163228

Your UITapGestureRecognizer's target should be self and not the UIImageView itself.

Upvotes: 4

Related Questions