Faisal Syed Faisal Syed - 9 days ago 6
iOS Question

Updating UI in TableViewController: Who's responsible- The table or cell?

Let's say I'm retrieving a bunch of data from a service and parsing it in JSON.

When I set my cell's UI elements to the appropriate values based on the retrieved data, is it better to set it up in the table view cellForRowAtIndexPathMethod, or should I do it in the UITableViewCell in the didSet method for my JSON object?

Answer

Once you have your JSON parsed, you should call reloadData on you TableView.

Then the best approach I think would be to have a method in the cell allowing you to set it up like let's say

setup(withUser: User) {}

and call it from you cellForRowAtIndexPath method.

Comments