25、[ iOS ] TableView 点击空白隐藏键盘

由于Cell阻挡事件传递的原因,正常情况下点击 tableView 是不会实现隐藏键盘的功能,我们可以给其添加一个Tap点击手势来实现。

    UITapGestureRecognizer *tableViewGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tableViewTouchInSide)];
    tableViewGesture.numberOfTapsRequired = 1;//几个手指点击
    tableViewGesture.cancelsTouchesInView = NO;//是否取消点击处的其他action
    [tableView addGestureRecognizer:tableViewGesture];

实现其方法

// ------tableView 上添加的自定义手势
- (void)tableViewTouchInSide{
    // ------结束编辑,隐藏键盘
    [self.view endEditing:YES];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容