Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set cursor focus on TextField when form load in Objective C

I have 3 textfields (Username, Password, Confirm Password). When the form loads I wish for the cursor to start off in the textfield Username when the form is first displayed. Please give me some advice. Thank in advance.

like image 332
user1628083 Avatar asked Sep 14 '12 08:09

user1628083


1 Answers

[usernameTextField becomeFirstResponder];

This should provide you with the desired result. You can read about the responder chain here if you want to understand more about the mechanism.

Edit:

My bad, I thought you meant UITextField (Cocoa Touch).

Use the NSWindow makeFirstResponder: method, not this method, to make an object the first responder. Never invoke this method directly.

[window makeFirstResponder:usernameTextField];
like image 126
Alexander Avatar answered Mar 14 '23 20:03

Alexander