Faisal Syed Faisal Syed - 1 year ago 90
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download