Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem showing/hiding keyboard in iPhone app

In my iPhone app, I am facing some problems related to keyboard show/hide behavior.

I have three text fields; when the third text field is clicked, I want to display a UIPickerView and hide the keyboard for that text field. That I can do.

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

So what should I do to make the picker visible by itself and not to display any keyboard at that time?

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 like

enter image description here

like image 440
ios Avatar asked Dec 17 '22 15:12

ios


1 Answers

Keep three textfields as member of the controller.

- (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 will help you.

like image 165
Adarsh V C Avatar answered Jan 11 '23 11:01

Adarsh V C