UIButton not working when single tap gesture is added to superview

Andrew picture Andrew · Jan 10, 2011 · Viewed 23.5k times · Source

I have a UIButton set up and hooked up to an action in my view controller as usual. Just this by itself works fine.

Now, I have added the following to my view controller to set up a single tap:

- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer * singleTapGesture = [[UITapGestureRecognizer alloc] 
                                             initWithTarget:self
                                             action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleTapGesture];
[singleTapGesture release]; }

Now, every time I tap the button it looks like it was tapped but it fires the gesture recognizer code instead of the button action.

How can I make it so that the button works when I tap the button and the tap gesture works when I tap anywhere else in the view?

Answer

vdaubry picture vdaubry · Jan 21, 2011

Your problem is similar to this question which hopefully has been answered ;)

UIButton inside a view that has a UITapGestureRecognizer