07 Nov 2009
iPhone Tip: Automatic Focus for Text Input
Google popularized this trend in web forms years ago. When I go to the Google homepage, the page automatically puts the cursor in the search text box, so that I can immediately start typing. In Things on the iPhone, when I start to add a new item, the "New To Do" page automatically selects the Title text field. Again, I can immediately start typing. This autofocus is very easy to achieve: simply call [myUITextField becomeFirstResponder]. Changing the keyboard style is equally trivial: myUITextField.keyboardType = UIKeyboardTypeEmailAddress. Both are attributes of the UITextInputTraits protocol.