fill the void

Posted
7 November 2009 @ 1pm

Tagged
development

3 Comments

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.

// Automatically highlight the field and change to email keyboard.
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
[cell.field becomeFirstResponder];
cell.field.keyboardType = UIKeyboardTypeEmailAddress;

3 Comments

[...] This post was mentioned on Twitter by bdunagan, Objective-C. Objective-C said: FillTheVoid: iPhone Tip: Automatic Focus for Text Input: Google popularized this trend in web forms years ago. When… http://bit.ly/3d2ZVQ [...]


Posted by
JohnB
8 November 2009 @ 11am

Oh my gawd! Brian has a blog! What is the world coming to? This Internet fad has now clearly gone too far.


Posted by
bdunagan
8 November 2009 @ 12pm

@JohnB: Man, *you* convinced me to start a blog. I wanted to hire you at WildPackets before I’d even met you solely because of your blog, and that’s when I realized I should start one. Your “d efine” post was awesome.


Leave a Comment