user2988343
user2988343

Reputation: 215

How to force the text field to begin editing?

I'm using an alert view and the options are to change one of the values that are wrong so what I want to do is when the user selects which value he wants to change the text field corresponding to the value start editing.

Upvotes: 9

Views: 5324

Answers (3)

Gerges Eid
Gerges Eid

Reputation: 1075

Swift 4.2

Write this line of code in viewDidLoad

textField.becomeFirstResponder()

Upvotes: 3

neilco
neilco

Reputation: 8012

The correct way is the instruct the UITextField to receive focus via becomeFirstResponder:

if (buttonIndex == 0) {
    [self.givenVin becomeFirstResponder];
    NSLog(@"edit ");
} else if (buttonIndex == 1) {
    [self.givenVout becomeFirstResponder];
}

Upvotes: 3

dsafa
dsafa

Reputation: 793

If you have named a UITextField givenVin, then you could try with:

[self.givenVin becomeFirstResponder];

Upvotes: 13

Related Questions