简体   繁体   中英

How to dismiss keyboard on second time selecting first textfield?

I'm trying to dismiss keyboard on textfield did begin editing. First time selecting that textfield works fine, But in second time after resigning second textfield first textfield doesn't resign keyboard. I tried hard but not get result

Can any one help me.

Thanks in advance.

You can hide keyboard by own method.

For Eg.

-(IBAction)hideKeyboard:(id)sender {

     if (sender == txt1) {

       [txt2 becomeFirstResponder];
     }

     else if (sender == txt2) {

       [txt2 resignFirstResponder];
     }
}

Bind both of textfields with 'Did End On Exit' method in xib.

After resigning first, it'll focus on 2nd. Then after resigning 2nd, keyboard will be dismissed. you can continue with many textfields in this manner.

It'll work definately.

Thanks.

Implement textField's delegate to all the textFields to your class.

And use this one:

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

try this...

-(void)textFieldDidBeginEditing:(UITextField *)textField{
        if (textField == yourTextfield1) {
            [textField resignFirstResponder];
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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