Do not change the height in this way. Instead, when you know you want to change the height of the cell, call (in any function):
self.tableView.beginUpdates() self.tableView.endUpdates()
These calls notify the tableView to check for height changes. Then do the delegate override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat and specify the correct height for each cell. The change in height will be animated automatically. You can return UITableViewAutomaticDimension for elements that do not have an explicit height for.
I would not suggest doing such actions from cellForRowAtIndexPath , however, but in one that responds, for example, by pressing didSelectRowAtIndexPath . In one of my classes, I:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if indexPath == self.selectedIndexPath { self.selectedIndexPath = nil }else{ self.selectedIndexPath = indexPath } } internal var selectedIndexPath: NSIndexPath? { didSet{
source share