UITextField focus

IphoneTextinput

Iphone Problem Overview


How can I programmatically assign focus to a specific UITextField in a view? I have several fields and on view display, I'd like to put the cursor on a specific field, not the first one at top.

Iphone Solutions


Solution 1 - Iphone

Try doing this in viewWillAppear:

[desiredField becomeFirstResponder];

By making the field the first responder, it have focus and the keyboard will be displayed.

Solution 2 - Iphone

Set the first responder for your view to be the text field. This can be done in IB.

Solution 3 - Iphone

In swift:

desiredField.becomeFirstResponder()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobin JamiesonView Question on Stackoverflow
Solution 1 - IphoneAlexi GrooveView Answer on Stackoverflow
Solution 2 - IphoneDan LorencView Answer on Stackoverflow
Solution 3 - IphoneMennoView Answer on Stackoverflow