Last Updated: February 25, 2016
·
1.468K
· Damon Aw

Moving keyboard up when tapping on a textfield

Update
If you wish to use this, you MUST make sure [super viewWillAppear:YES] is called if you do intend to override the viewWillAppear method. That's where the magic happens.

Tip

If you use a UITableViewController and embed a textfield into one of the cells, the cell will scroll to ensure it will NOT be covered by the keyboard when the textfield is tapped on.

Free behavior rocks. No need to implement troublesome methods for simple views for login/logout.

But isn't it hard to customize a UITableViewController to look like a login screen?

Absolutely not.

  1. For a simple login screen, just drag a UIView into the table header (or instantiate one for tableHeaderView and tableFooterView.)

  2. Make the tableview to grouped and use STATIC cells, create the desired number of cells.

  3. Drag textfields into them, set the textfield border style to none.

  4. Drink a martini and chill?

For static cells to work, your controller must be a UITableViewController.

(A little further customization can be done in StoryBoard, just remove the selection, disclosure checkmark etc, your table cells will look liked a grouped textbox =))
Picture