今天遇到一个问题,先描述下吧:
storyboard中拖了个tableviewController,在tableview的自定义cell中拖了个textfield ,这时点击tableview不回收键盘了。 就想到了手势,为了让手势不与cell的点击事件冲突就有了这个方法:(参考文章:http://blog.csdn.net/wangfeng2500/article/details/50164261)
<pre>UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
gestureRecognizer.numberOfTapsRequired = 1;
gestureRecognizer.cancelsTouchesInView = NO;
[self.tableView addGestureRecognizer:gestureRecognizer];
</pre>
<pre>
- (void) hideKeyboard {
[textfield1 resignFirstResponder];
[textfield2 resignFirstResponder];
}
</pre>
网友评论