Tony
Tony

Reputation: 97

Make "Done" button work on TextField Keyboard

When adding a textfield, the keyboard opens correctly, however I cannot get the done button to work properly. I know thee are other similar posts, however for whatever reason they do not seem to work for me.

When I say "not work" i mean the keyboard does not close.

Any suggestions would be appreciated.

Upvotes: 1

Views: 3685

Answers (2)

Ryan Poolos
Ryan Poolos

Reputation: 18561

I believe this is what you're looking for. Its a UITextFieldDelegate callback thats called anytime the Done/Return button is used on the keyboard.

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

You'll need the delegate in your interface

@interface Class : UIViewController <UITextFieldDelegate>

If you're textfield is in a ModalViewController using the FormSheet style you need this as well.

- (BOOL)disablesAutomaticKeyboardDismissal
{
    return NO;
}

Upvotes: 1

self
self

Reputation: 1215

Add this and let me know:

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

Remember to add the viewController as delegate of your text field

Upvotes: 5

Related Questions