I have read several articles about UITableView, including the official doc and some on SO. But my situation seems to be different.
I want to update the Table each time the view loaded. And I must fetch the data using HTTP request.
What I got now is:
- When enter the table view, I should use a non-synchronous HTTP request to update the data. Because I don’t want the main thread to wait. One place to do that, is in the
tableView:cellForRowAtIndexPath:method. So I return 0 for no data exist at the beginning. - When I get the HTTP respond, I update rows on main thread using
beginUpdates endUpdates insertRowsAtIndexPaths:withRowAnimation: - And I must update the “Data Source” at the same time, but how to do that?
Or should I make a daemon thread and update my data every once in a while? So that the data will be ready when TableView is loaded.
You would do it like this:
viewWillAppear, reset everything. Start loading your data.[self.tableView reloadData];In all of your
UITableViewDataSourcemethods you would need to check whether you’ve got the data already or not. If not, you return the placeholder data.