iOS开发-cell里面有textField,出现键盘自动上移

Posted sunshine-zzz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS开发-cell里面有textField,出现键盘自动上移相关的知识,希望对你有一定的参考价值。

当UITableViewCell里有UITextfield,当输入时键盘遮盖了UITextField,UITableView是会自动上移,当如果要让tableView自动滚动的话,还需要设置一下tableView的contentInset。接下来介绍一下实现步骤,  首先监听键盘出现和消失:  [[ NSNotificationCenter defaultCenter ] addObserver : self selector : @selector (keyboardWillShow:) name : UIKeyboardWillShowNotification object : nil ];     [[ NSNotificationCenter defaultCenter ] addObserver : self selector : @selector (keyboardWillHide:) name : UIKeyboardWillHideNotification object : nil ];
具体实现方法: -( void )keyboardWillShow:( NSNotification *)note     CGRect keyBoardRect=[note. userInfo [ UIKeyboardFrameEndUserInfoKey ] CGRectValue ];     self . myTableView . contentInset = UIEdgeInsetsMake ( 0 , 0 , keyBoardRect. size . height , 0 ); #pragma mark 键盘消失 -( void )keyboardWillHide:( NSNotification *)note     self . myTableView . contentInset = UIEdgeInsetsZero ;

以上是关于iOS开发-cell里面有textField,出现键盘自动上移的主要内容,如果未能解决你的问题,请参考以下文章