My program basically looks like this:
UIViewController -> Custom UIView -> [Array of UIImageView]
My problem is that my recognizer’s action method is never called. I’ve already set the userInteractionEnabled attribute of my UIImageViews to YES.
On my View Controller’s viewDidLoad:
- (void)viewDidLoad
{
NSEnumerator *enumerator = [grid.subviews objectEnumerator];
UIImageView *view;
UITapGestureRecognizer *recognizer;
while((view = [enumerator nextObject])){
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openDeal:)];
view.userInteractionEnabled = YES;
recognizer.delegate = self;
recognizer.numberOfTapsRequired = 1;
[view addGestureRecognizer:recognizer];
NSLog(@"%d", (int)view.userInteractionEnabled);
[recognizer release];
}
[super viewDidLoad];
}
and openDeal is defined as such:
-(void) openDeal:(UITapGestureRecognizer *) recognizer{
NSLog(@"%@",[NSString stringWithFormat:@"%d", recognizer.view.tag]);
}
I had the same issue and later found out that I was assigning the same gesture recognizer instance to another view. Gesture recognizers can be associated to a single view only (you can verify that through UIGestureRecognizer’s view property).
Make sure you are not reusing your recognizers somewhere else in the code.