UITableViewController and UITextField keyboard

后端 未结 3 752
-上瘾入骨i
-上瘾入骨i 2021-02-08 12:31

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. Whe

3条回答
  •  爱一瞬间的悲伤
    2021-02-08 13:02

    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.

提交回复
热议问题