[iOS]UITableViewController完毕收回键盘操作

UITableViewController 本身可以实现键盘适配(cell中控件焦点会移动到键盘上方

在做键盘收回的时候思考过例如以下方案

1、tableview加入点击事件

结果:点击事件和tableview的didselect 冲突,导致didselect失效

2、scrollview代理滚动收回键盘

结果:目的能够达到。可是当点击textfield的时候,此时键盘会出现之后直接收回。原因是先适配→调用scrollview代理。

最后採用例如以下方案 如图:



    <span style="font-family: Arial, Helvetica, sans-serif;">_sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];</span>
    _sureBtn.frame = CGRectMake(self.view.size.width-60, 5, 50, 28);
    _sureBtn.backgroundColor = [UIColor colorWithRed:0.150 green:0.662 blue:0.915 alpha:1.000];
    _sureBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    _sureBtn.layer.cornerRadius = 5.0;
    [_sureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [_sureBtn addTarget:self action:@selector(changeRemarks) forControlEvents:UIControlEventTouchUpInside];
    _view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];
    _view.backgroundColor=[UIColor whiteColor];
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.5)];
    line.backgroundColor = [UIColor blackColor];
    [_view addSubview:line];
    [_view addSubview:_sureBtn];


在使用的时候,对Textfield进例如以下处理

 _begoodatField.inputAccessoryView = _view;

假设是tableview中cell的文本框

则须要在定义一个暂时textfield。

使用的时候 

 _xuexiaoField=cellMenu.celltext;
 _xuexiaoField.inputAccessoryView = _view;//<span style="font-family: Arial, Helvetica, sans-serif;">cellMenu为自己定义cell的名字</span>
附上确定button方法
- (void)changeRemarks
{
    [_nicktextField resignFirstResponder];
    [_xuexiaoField resignFirstResponder];
    [_begoodatField resignFirstResponder ];
    [_bumenField resignFirstResponder ];
}



https://github.com/KKKKaras/SureBtnDemo


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值