iOS 8 auto-sizing UITableViewCell with UITextView

前端 未结 6 1535
余生分开走
余生分开走 2021-02-12 12:11

iOS 8 introduced a way for tableViews to automatically adjust their cell\'s height based on their content (via AutoLayout).

// in viewDidLoad:
tableView.rowHeigh         


        
6条回答
  •  暖寄归人
    2021-02-12 12:57

    Reload the cell in the textViewDidBeginEditing: method of your UITextViewDelegate

    [self.tableView beginUpdates];
    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];
    

    Obviously you should change the indexpath to the correct one for your cell. This will get the cell to update its constraints and resize itself.

提交回复
热议问题