jpd
jpd

Reputation: 381

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.

Upvotes: 1

Views: 177

Answers (3)

Paras Joshi
Paras Joshi

Reputation: 20541

try this...

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

Upvotes: 0

Anoop Vaidya
Anoop Vaidya

Reputation: 46563

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

And use this one:

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

Upvotes: 0

Manann Sseth
Manann Sseth

Reputation: 2745

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.

Upvotes: 1

Related Questions