Issue with showing / hiding keyboard in iPhone application

In my iPhone app, I ran into some issues related to showing the keyboard / hiding the keyboard.

I have three text fields; when I click on the third text box, I want to display the UIPickerView and hide the keyboard for this text box. I can do it.

Now the problem is that if the keyboard of the first or second text field is visible, and I click on the third text field, the collector becomes visible, but it appears behind the keyboard (it is located only behind the keyboard the first or second text field).

So, what should I do to make the assembler visible by itself and not display the keyboard on it?

Here is the code: -

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

 if (textField==thirdTextField) { [scroll setFrame:CGRectMake(00, 48, 320, 160)]; [scroll setContentSize:CGSizeMake(320,335)]; [picker setHidden:NO]; [tool1 setFrame:CGRectMake(0,180,320,44)]; [tool1 setHidden:NO]; [self.picker reloadAllComponents]; [firtTextField resignFirstResponder]; [secondTextField resignFirstResponder]; [thirdTextField resignFirstResponder]; } else { [scroll setFrame:CGRectMake(00, 48, 320, 200)]; [scroll setContentSize:CGSizeMake(320,335)]; [tool1 setHidden:NO]; [tool1 setFrame:CGRectMake(0,220,320,44)]; } } 

the problem is similar to

enter image description here

+4
source share
5 answers

Store three text fields as a controller element.

 - (void)textFieldDidBeginEditing:(UITextField *)textField { if(textField == 3rdTextField){ [self.firstTextField resignFirstResponder]; [self.secondTextField resignFirstResponder]; [self.thirdTextField resignFirstResponder]; } } - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ if(textField==3rdTextField){ [firstTextField resignFirstResponder]; [secondTextField resignFirstResponder]; } else if(textField==secondTextField){ [firstTextField resignFirstResponder]; [3rdTextField resignFirstResponder]; } else if(textField==firstTextField){ [secondTextField resignFirstResponder]; [3rdTextField resignFirstResponder]; } return YES; } 

Hope this helps you.

+7
source

Call

 [yourTextField resignFirstResponder] 

on all other text fields so that their keyboard disappears.

+3
source

use resignFirstResponder methods and text fields. [textField resignFirstResponder] , which will hide the keyboard.

+1
source

Then use the notification when the keyboard becomes visible and has the logical name isPickerVisible.
When the collector becomes visible, set isPickerVisible to TRUE.
In the keyboardDidShow method, check if the collector is visible or not. If it is visible, hide it.
Adding a notification:

 [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(keyboardDidShow:)
name:UIKeyboardWillShowNotification
object:nil];
And the method ...
 - (void)keyboardDidShow:(NSNotification*)notif { if(isPickerVisible) { [self hidePicker]; } } 

Hope this helps ...

+1
source

B - (BOOL) textFieldShouldBeginEditing: (UITextField *) the textField method uses resignFirstResponder for the entire text field except the third textFied: -

 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { if(textField==thirdTextField) { [firstTextField resignFirstResponder]; [secondTextField resignFirstResponder]; [textField resignFirstResponder]; [self showPickerView]; } return YES; } 
0
source

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


All Articles