I have an autocomplete table that I create the frame for when the user types anything in a search bar button item. The problem is, I want to be able to dismiss the tableview when the user touches outside of it or the table, so naturally I added a tap touch recogniser to the main view.
Problem is, the view "hijacks" the touches from the table, so when you try to touch the table it dismisses it (which makes perfect sense as the table is a subview of that UIView)
Anyone have any smart solutions? (My initial hunch is to put the UITableView in a new window on top of the view's window, but I would prefer if there was something more elegant)
Maybe you can try
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view.superview.superview isKindOfClass:[UITableView class]]) return NO;
else return YES;
}
//Init recognizer
UIGestureRecognizer *gestureRecognizer;
gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[gestureRecognizer setCancelsTouchesInView:NO];
[self.view addGestureRecognizer:gestureRecognizer];
self.tapRecognizer = (UITapGestureRecognizer *)gestureRecognizer;
gestureRecognizer.delegate = self;
[gestureRecognizer release];
and put some stuff for your gesture in
- (void)handleTap:(UITapGestureRecognizer *)recognizer {
}
Hope it helps :)