1

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 :)

Thomas
  • 2,356
  • 7
  • 23
  • 59
  • Create a protocol, have your view controller implement it and set itself as the delegate on the cell and then call the protocol method from the cell - Have you tried any of this? – Paulw11 Jul 24 '15 at 22:58
  • [Check the answer here,you should get the idea of doing it :)][1] [1]: http://stackoverflow.com/questions/31485558/uitextview-and-cell-dynamically-update-height-based-on-content-of-textview/31486972#31486972 – Aditya Koukuntla Jul 24 '15 at 23:18

1 Answers1

0

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.

TomSwift
  • 39,369
  • 12
  • 121
  • 149
  • Just out of curiosity, is posting a notification that calls a method that will refresh the TableViewCell a bad practice? Or is it just that there's multiple ways to refresh a TableViewCell do this – Thomas Aug 02 '15 at 22:56
  • I wouldn't say it is a bad practice, no. Sometimes you just need to be pragmatic and pick what works for the effort you're willing to spend. – TomSwift Aug 03 '15 at 16:32