cell上多个textField上的问题

在viewDidLoad方法里使用

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

然后调用UITextFieldDelegate代理方法

-(void)keyboardWillShow:(NSNotification*)note

{

    CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

    self.tabelView.contentInset=UIEdgeInsetsMake(0,0, keyBoardRect.size.height+100,0);

}

#pragma mark 键盘消失

-(void)keyboardWillHide:(NSNotification*)note{  

  self.tabelView.contentInset = UIEdgeInsetsZero;

}

如果是cell上的多个textfield的点击事件可以这样写:

//首先在cellForRowAtIndexPath:方法里给textfield绑定tag 添加点击事件

 cell.nameTf.tag= indexPath.row;

[cell.nameTf addTarget:self action:@selector(changedTextField:) forControlEvents:UIControlEventEditingChanged];

然后调用点击事件和代理方法

#pragma mark --- target && UITextFieldDelegate

- (void)changedTextField:(UITextField*)textField{

UITextField*tempTextField = (UITextField*)textField;

    NSLog(@"tag------%ld;值是---%@",tempTextField.tag,tempTextField.text);

    if(tempTextField.tag==0) {

        NSString*str = tempTextField.text;

        NSLog(@"%@",str);

 }elseif(tempTextField.tag==1){

        NSString*str = tempTextField.text;

        NSLog(@"11===%@",str);

    }elseif(tempTextField.tag==2){

        NSString*str = tempTextField.text;

        NSLog(@"22===%@",str);

    }

}

- (BOOL)textFieldShouldReturn:(UITextField*)textField{

//监听键盘return键的点击,隐藏键盘

    [textFieldresignFirstResponder];

    return YES;

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容