UItextField delegate not working

In my iPad app, I have two text fields. One shows the normal default text box, and the other should display the collector as its input type.

The problem is that I use txt1 , which displays the default keyboard, and then when I touch the second text field, the txt1 keyboard remains visible.

I also wrote [txt1 resignFirstResponder]; [txt2 resignFirstResponder]; when displaying the collector.

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

What am I missing?

+4
source share
6 answers

Enter 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 can solve your problem ......

+2
source

You need to implement below method to exit the keyboard ...

 -(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } 
+2
source
  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

+2
source

Do you have this method implemented?

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

In your viewDidLoad method write this,

 txt2.inputView = pickerView; 

and other resignFirstResponder codes should be placed correctly, while on Tapping txt2 you will immediately get a pickerview instead of Keyboard.

0
source

if the delegate property implemented UITextFieldDelegates in the header file, if not, check

0
source

Source: https://habr.com/ru/post/1403051/


All Articles