UItextField Delegate not working

梦想的初衷 提交于 2019-12-12 11:35:15

问题


In my iPad app I have two textfields. One displays the normal, default textfield and the other should display a picker as its input view.

Problem is, once I use the txt1 which displays default keyboard and then when I touch the 2nd textField the txt1 keyboard is staying visible.

I have also written [txt1 resignFirstResponder]; [txt2 resignFirstResponder]; while displaying the picker.

I have checked the txt1 IBOutlet connection and the delegate assignment, those seem to be correct.

What am I missing?


回答1:


Write the following code :

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
   if(textField == txt1)
   {
       return YES;
   }
   else
   {
       return NO; // Write the code for displaying UIPickerView instead of the Keyboard.
   }
}

Hope this might solve your issue......




回答2:


 txt2.userInteractionEnabled = NO;

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if(textField == txt1)
    {
        [txt2 resignFirstResponder];
        // code for Hide Picker 
        return YES;
    }
    else {
       // [txt2 resignFirstResponder];
        [txt1 resignFirstResponder];
        // code for go in picker 
        return YES;
    }
}

for more information




回答3:


You have to implement below method to resign Keyboard......

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
   [textField resignFirstResponder];
   return YES;
}



回答4:


Have u implemented this method ??

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
     [textField resignFirstResponder];
     return YES;
}



回答5:


In your viewDidLoad method write this,

txt2.inputView = pickerView;

and other resignFirstResponder codes should be placed correctly , by this on Tapping txt2, you will directly get pickerview instead of Keyboard.




回答6:


did you implement the delegates property of UITextFieldDelegates to in the header file, if not do that and check



来源:https://stackoverflow.com/questions/9837652/uitextfield-delegate-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!