Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewController and UITextField keyboard

I have a UITableViewController with a grouped static UITableView. I am defining the cells for my static table view on the storyboard. One of the cells has a textfield in it. When this textfield is called, the keyboard pops up, however, the tableview is not automatically resizing like it normally would on a table view controller. So now the keyboard is partially covering the textfield and I can't scroll up.

My understanding is that when you are using a UITableViewController and a tableview, the viewable area should automatically shrink when the keyboard is called. It does work as intended in other parts of my app, just not with this static table view. Does it not work with static tables? Is there something else I am missing? Is there an easy way to solve this?

Thanks

like image 235
Keith Avatar asked Jul 03 '12 15:07

Keith


2 Answers

Answer

It has nothing to do with static cells. They should work.

If your controller is already a UITableViewController, check if you used the method viewWillAppear. If you did, you have to call [super viewWillAppear:YES] to get the 'automatic behavior' to work.

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES]; // This line is needed for the 'auto slide up'
   // Do other stuff
}

This problem turns up easily because the boilerplate code for the controllers don't come with the viewWillAppear method call and if you define it in your controller, you override it.

Extra Information

Look at this link.

Apple Table View Programming Guide

Note: UITableViewController has new capabilities in iOS 3.0. A table-view controller supports inline editing of table-view rows; if, for example, rows have embedded text fields in editing mode, it scrolls the row being edited above the virtual keyboard that is displayed.... blah....

The important bit

The UITableViewController class implements the foregoing behavior by overriding loadView, viewWillAppear:, and other methods inherited from UIViewController. In your subclass of UITableViewController, you may also override these methods to acquire specialized behavior. If you do override these methods, be sure to invoke the superclass implementation of the method, usually as the first method call, to get the default behavior.

like image 171
Damon Aw Avatar answered Nov 10 '22 05:11

Damon Aw


For Swift

override func viewWillAppear(animated: Bool) {

   super.viewWillAppear(animated)

}
like image 37
Paul S. Avatar answered Nov 10 '22 07:11

Paul S.