Height change
Basically, there are two ways:
The first is to actually reload the cell (not the table). Rebooting will cause a new heightForRow (don't forget to clear the cache if you cache sizes), which will return the correct new height:
let indexPaths = [NSIndexPath(forRow: ~the rows in question~, inSection: 0)] self.table.reloadRowsAtIndexPaths(indexPaths, withRowAnimation: .Automatic)
(Note that this often requires reloading more than one row, especially if you select / deselect, you need to reload all rows.)
If, however, you ONLY want to change the cell size and the content as such, and you have not actually changed the contents of the data ... for example:
you clicked a button and you assigned a new local text in the output box (possibly help text):
You only changed the LAYOUT cells. for example, you made the font larger or changed the text block field so that the height of the text block changed, so the height of the whole cell changed:
In this case, instead of reloading, just call the following, which causes the tableview to basically do all the animations, and for this it needs new heights, so it asks:
self.table.beginUpdates() self.table.endUpdates()
True decision
I understand what the problem is. You are trying to change the cell height from the actual cell, but you will not succeed β and you should not do this. Look, a cell is a view, and a view should not have any idea of ββits data - a view is what it represents. If you need any changes, you should inform your controller about this. You can use notifications for this, but preferably protocols / delegates.
So, first you create a protocol in your cell that will be used to inform the controller that there is a change:
protocol MyCellDelegate { func buttonTappedForCell(cell : UITableViewCell) }
Now you need to match this protocol in your view controller, which contains the table:
class MyClassWithTableView : MyCellDelegate
Finally, you need to declare a delegate in the cell:
class MyCell { var delegate : MyCellDelegate }
And assign it in the cell configuration, which you probably have in the view controller:
cell.delegate = self
This is the basic setting for all delegates / protocols, and now, when you click on your button, you can redirect the action to your controller:
@IBAction myButtonTouchUpInside() { self.delegate.buttonTappedForCell(self) }
When doing all this, proceed as in Part 1. That is, a pair of reloadRowsAtIndexPaths or beginUpdates / endUpdates , as described above.
Hope this helps!