Resize UITableViewCell containing UITextView upon typing

后端 未结 11 2139
感动是毒
感动是毒 2020-12-23 10:19

I have an UITableViewController that contains a custom cell. Each cell was created using a nib and contains a single non-scrollable UITextView. I have added constraints insi

11条回答
  •  太阳男子
    2020-12-23 11:04

    The trick to immediately update the tableview cells height in a smooth way without dismissing the keyboard is to run the following snippet to be called in the textViewDidChange event after you set the size of the textView or other contents you have in the cell:

    [tableView beginUpdates];
    [tableView endUpdates];
    

    However this will may not be enough. You should also make sure the tableView has enough elasticity to keep the same contentOffset. You get that elasticity by setting the tableView contentInset bottom. I suggest this elasticity value to be at least the maximum distance you need from the bottom of the last cell to the bottom of the tableView. For instance, it could be the height of the keyboard.

    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardHeight, 0);
    

    For more details and some useful extra features around this matter please check out the following link: Resize and move UITableViewCell smoothly without dismissing keyboard

提交回复
热议问题