Reputation: 11696
I am using UIGestureRecognizer to resign the keyboard when the user taps outside of the text fields. This is working with no problem and I have managed to exclude 3 buttons but now that I have added 2 tables into my page, I cannot find a way to exclude them from the shouldReceiveTouch:
This is the relevant code:
- (void)viewDidLoad
{
.....
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
[[self view] addGestureRecognizer:gestureRecognizer];
[gestureRecognizer setDelegate:self];
}
- (void)hideKeyboard
{
[tradeQuantity resignFirstResponder];
[tradeSymbol resignFirstResponder];
[limitPrice resignFirstResponder];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (touch.view == placeTradeButton)
{
return NO;
} else if (touch.view == resetValuesButton)
{
return NO;
} else if (touch.view == refreshDataButton)
{
return NO;
} else if (touch.view == secHoldingsTable)
{
return NO;
} else if (touch.view == tradeTicketsTable)
{
return NO;
}
return YES;
}
How do I exclude the tables?
Upvotes: 2
Views: 783
Reputation: 11696
I haven't found the answer to my question but I did find a workaround that does what I need. Instead of trying to find out how to exclude a table, I did the reverse.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (touch.view == [self view])
{
return YES;
}
return NO;
}
Upvotes: 2