我正在尝试让键盘在点击空白区域时消失(文本字段位于tableViewCells中)我可以使用以下代码执行此操作
-(void) initTapGesture{ //calling in viewDidLoad
self.singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTappingView)];
self.singleTap.numberOfTapsRequired = 1;
self.singleTap.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:self.singleTap];
}
-(void)onTappingView{
[self.tableView endEditing:YES]; // or [self.view endEditing:YES];
}
但在此之后,tableView单元格的didSelectRowAtIndexPath委托方法根本没有被调用。我该怎么办?
我还尝试了以下用于onTappingView函数的代码:它不起作用:
-(void)onTappingView{
RegistrationTabelViewCell *cell=(RegistrationTabelViewCell*)[self.registerationTabelView cellForRowAtIndexPath:self.currentCellIndexPath];
[cell.textField resignFirstResponder];
}