Jack Humphries
Jack Humphries

Reputation: 13267

becomeFirstResponder Question

I have a UITextField that the user enters their name into. When they tap a button, my app checks to make sure that they actually entered something. If they didn't I have an alert view come up stating so, and then below that I have this code:

[textField becomeFirstResponder];

The only problem is, when the user hits the ok button on the alert view, the text field does not become selected so that the user can enter text into it, instead they have to tap it manually, which defeats the purpose of the code. It's like the alert view is preventing this from happening. What do you suggest I do? Thanks for your help!

Upvotes: 0

Views: 647

Answers (1)

Cyrille
Cyrille

Reputation: 25144

How do you show your alert? Do you call [textField becomeFirstResponder] right after the [alert show] ?

If so, that's the problem. You should register your controller as your alert's delegate, then call becomeFirstResponder when you receive the alertView:didDismissWithButtonIndex: message.

Take a look at the UIAlertViewDelegate protocol.

Upvotes: 2

Related Questions