0

I am looking for a sample code, showing what is the best way to populate an UITableView with the response of JSON data. Let me explain in details.

The situation is the following:

When I navigate to the current view controller(the one with the table view), I send a request to my server in order to send me a JSON response. Meanwhile, I display an Activity indicator in foreground, showing the user that an activity is loading. When the response arrives, I need to parse it, store it with Core Data and then populate my Table View with the data.

My question is:

What is the best practice, best way to populate the table view? Should I grab the whole data that I need and use a NSArray while populating the table view? Or may be use NSFetchedResultsController for this purpose? How should I reload the table view? Is [self.tableView reloadData] good enough for my purpose?

I hope I was clear enough with my question(s) :) Thanks in advance

4

1 回答 1

1

If the view controller always needs to call out to the server on every view, you can simply retain the response dictionary (or convert it to your own plain objects and retain an array of those) and bind the tableview in the afnetworking callback.

If you do not always need to call it, you could save the objects to core data on call back then create your retained NSFetchedResultsController and set the delegate on it (just in case the data gets modified/altered elsewhere).

于 2012-12-26T19:13:04.343 回答