简单的在UITableView中隐藏键盘

1,在UITableView中,要求点击非编辑区域隐藏键盘

 

 

2,在一般控制器中,实现点击"空白"区域隐藏键盘的方法

 

代码如下:

UITableView

//UITableView 懒加载

- (UITableView*)tableView {

    if (!_tableView) {

        _tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStyleGrouped];

        _tableView.delegate = self;

        _tableView.dataSource = self;

        //添加tap手势,隐藏键盘

        UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBorad)];

        [_tableView addGestureRecognizer:tap];

        

    }

    return _tableView;

}

 

//隐藏键盘方法

- (void)hideKeyBorad {

    [self.view endEditing:YES];

}

 

 

UIView

//点击视图的区域隐藏键盘

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [self.view endEditing:YES];

}

posted @ 2015-03-25 14:52  花园晓雨  阅读(353)  评论(0)    收藏  举报