2

当用户在文本字段之外点击时,我正在使用 UIGestureRecognizer 退出键盘。这没有问题,我已经设法排除了 3 个按钮,但是现在我在页面中添加了 2 个表格,我找不到将它们从 shouldReceiveTouch 中排除的方法:

这是相关代码:

- (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;
}

如何排除表格?

4

1 回答 1

2

我还没有找到我的问题的答案,但我确实找到了一种解决方法,可以满足我的需要。我没有尝试找出如何排除表格,而是相反。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{            
if (touch.view == [self view])
{
    return YES;
}
return NO;
}
于 2012-04-29T14:41:04.813 回答