简体   繁体   English

UITextfield键盘辞职

[英]UITextfield keyboard resign

in my uitableview in each cell I'm having uitextfield when user edits the textfield and after pressing any other button on the screen the Keyboard is not resigning. 在用户单元的uitable视图中,当用户编辑文本字段时,我将拥有uitextfield,并且在按下屏幕上的任何其他按钮后,键盘不会退出。 I did the following in textfield delegates 我在textfield代表中做了以下工作

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    textfieldInCell = textField;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    textfieldInCell=nil;// this is the ivar i am using for each textfield in cell.
    return YES;
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    textfieldInCell=textField;
    // do the process...
    textfieldInCell=nil
}

I am also calling the shouldReturn delegate function once the user tapping on any other button but the keyboard is not resigning. 一旦用户点击其他任何按钮但键盘未退出,我也将调用shouldReturn委托函数。 Where am I going wrong? 我要去哪里错了?

have you bind delegate of textfield with your controller? 您是否已将文本字段的委托与您的控制器绑定? or did you check textFieldShouldReturn calling or not? 或者您是否检查了textFieldShouldReturn调用?

i think, binding is missing wit view controller in your case. 我认为,绑定在您的情况下丢失了视图控制器。

thanks 谢谢

add a line in your tableview where you are adding textfield. 在您要添加文本字段的tableview中添加一行。

<YOUR_TEXTFIELD>.delegate = YES;

Enjoy Programming 享受编程

first check that you give the delegate or not and give the delegate to UITextField after that when you call the method of button at that time resign this textfield like bellow... 首先检查是否给委托,然后将委托给UITextField ,然后在那时调用button的方法时,请像下面这样退出此文本字段...

-(IBAction)yourButton_Clicked(id)sender{

   [yourTextField resignFirstResponder];
   ////your code write here

}

Confirm that you bind the delegate of each textfield that you create with the view controller and add one line of code in textfield did end editing :- 确认您使用视图控制器绑定了您创建的每个文本字段的委托,并在文本字段中添加了一行代码,从而结束了编辑:-

-(void)textFieldDidEndEditing:(UITextField *)textField
{
   // add the following line
   [textField resignFirstResponder];
   textfieldInCell=textField;
   // do the process...
    textfieldInCell=nil 

}

you must try to assign tag value to textfield then in should return method you used that tag to hide the keyboard like this (if you assign the tag -1 then) 您必须尝试将标签值分配给文本字段,然后在应该返回使用该标签隐藏键盘的方法中(如果您将标签分配为-1,则该方法)

-(void)textFieldDidEndEditing:(UITextField *)textField{
    if(textField.tag==-1){
     [textField resignFirstResponder];
     }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM