[UITapGestureRecognizer tag]: unrecognized selector sent to instance

Neither UITapGestureRecognizer nor UIGestureRecognizer declares a property or method called tag.

You can't use it. That's why you're getting the error.

On a related note. I really don't like using tag in general. There is always a better way to do what you're doing without using tag.


Just Change your Selector Method with the following..and it will work

tapgesture will have the whole view which is tapped.. and then you can get the tag property from it as i have stated in following

-(void)action:(UITapGestureRecognizer *)tapGesture{

     NSLog(@"TESTING TAP");
        NSLog (@"%d",tapGesture.view.tag);

    }

You can use this..

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
                                         initWithTarget:self action:@selector(action:)];
[tapRecognizer setNumberOfTouchesRequired:1];
[tapRecognizer setDelegate:self];
imageView.userInteractionEnabled = YES;
imageView.tag = 1111;
[imageView addGestureRecognizer:tapRecognizer];

And in action try this..

-(void) action:(id)sender
  {
    NSLog(@"TESTING TAP");
    UITapGestureRecognizer *tapRecognizer = (UITapGestureRecognizer *)sender;
    NSLog (@"%d",[tapRecognizer.view tag]);
  }

Explaination:

UITapGestureRecognizer has not property like tag. but it has property view, from this property you can access the view with which UITapGestureRecognizer was attached.

Hope it will help you