Search code examples
iosswiftdelegationuitableview

Reload TableView from within Custom TableViewCell


How can I reload a TableView using delegation from within my CustomTableViewCell class?

Currently I'm doing it by calling this:

NSNotificationCenter.defaultCenter().postNotificationName(UIContentSizeCategoryDidChangeNotification, object: nil)

But I would like to do it through delegation so I can have more control over the animation and reload only that specific TableViewCell instead of the whole thing.

Any help is greatly appreciated :)


Solution

  • As @Paulw11 suggests in his comment, you can implement a delegate pattern to call back from your custom UITableViewCell to the controller. Be careful not to create any circular references (use weak properties!)

    You could also count on the fact that the UITableViewCell is child of the UITableView. That is, if you need to get to the UITableView (vs your controller) you can walk up the superview chain until you find it.