点击 UITableView 隐藏键盘

在 UITableView 上加手势

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
[self.tableView addGestureRecognizer:gestureRecognizer];
- (void) hideKeyboard {
[textField1 resignFirstResponder];
[textField2 resignFirstResponder];
...
...
}

ps:加上这句不会影响你 tableview 上的 action (button,cell selected...)

gestureRecognizer.cancelsTouchesInView = NO;

原帖地址: http://stackoverflow.com/questions/2321038/dismiss-keyboard-by-touching-background-of-uitableview
 

posted on 2012-03-23 12:16  uniy  阅读(5393)  评论(0编辑  收藏  举报

导航