Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update height of the cell with UITableViewAutomaticDimension?

I have a UITextView in a tableViewCell, and using the iOS 8 provided UITableViewAutomaticDimension approach listed here.

If user add new line to UITextView, and so textView, cell height should increase, how can I update height?

Tried:

cell.layoutIfNeeded()
cell.setNeedsUpdateConstraints()

These does not work.

If I reload cell, like

tableView.reloadRowsAtIndexPaths([iindexPath], withRowAnimation: .None)

this works, but then I need to deal with resign and show keyboard. I would avoid it. Any workaround?

like image 653
János Avatar asked Sep 10 '15 08:09

János


1 Answers

need to add following method:

func textViewDidChange(textView: UITextView) {

    tableView.beginUpdates()
    tableView.endUpdates()
}

it will update constraints without reloading tableview

like image 198
János Avatar answered Nov 04 '22 21:11

János