所以我有这个UITableView
包含几行,当点击一行时,另一个UIViewController
被推送特定行的详细信息。我的问题是我想通过屏幕上的任何触摸(也在UITableView
)上关闭键盘,但是当我这样做并单击UITableView
行时,键盘会关闭,但该didSelectRow
方法不起作用。ViewController
一旦单击单元格,它就不会推送新的。
同样反过来,一旦我更改它,您可以单击 TableView 单元格,键盘关闭并且另一个 ViewController 被推送,但是任何其他地方的触摸都不会关闭键盘。
我该怎么办?
- (IBAction)hideKeyboard:(id)sender
{
[tfFoodsSearchQuery resignFirstResponder];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UITableView class]])
{
// we touched a button, slider, or other UIControl
return YES; // handle the touch
}
NSLog(@"Touch");
return NO; // ignore the touch
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(hideKeyboard:)];
[self.view addGestureRecognizer:tap];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
gestureRecognizer.delegate = self;
[self.tvFoods addGestureRecognizer:gestureRecognizer];
}
谢谢!