I have a UITableView and UINavigationController, and I’d like to distinguish between two clicks: 1) normal click that selects a row and 2) a click that happens ANYWHERE else on the screen (other than the buttons on the UINavigationController). I wrote this code:
singleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(singleTapHandler:)];
singleTap.numberOfTapsRequired = 1;
The problem with this however is that it overrides the normal clicks that select a row.
I assume you’re putting the tap recognizer on either the
UIWindowitself, or the window’s sole subview. You need to give the tap recognizer a delegate, and that delegate needs to implementgestureRecognizer:shouldReceiveTouch:.In that method, you want to return
NOif the touch is in a button or if the touch is in a table view cell, andYESotherwise. You need to walk up the view hierarchy, starting with the view that the touch landed in, looking for either of those classes.