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:
tableView:cellForRowAtIndexPath:
method. So I return 0 for no data exist at the beginning. beginUpdates endUpdates insertRowsAtIndexPaths:withRowAnimation:
You would do it like this:
viewWillAppear
, reset everything. Start loading your data.[self.tableView reloadData];
In all of your UITableViewDataSource
methods you would need to check whether you've got the data already or not. If not, you return the placeholder data.
[yourtablename reloadData]; will help you relaod the data in the tableview, You can call this once you get the response from your server
I'm not sure there's a "best method" for what you're trying to accomplish here. I would suggest trying the method you have, and seeing if it provides an adequate user experience (whatever that means to you) and if it doesn't, try something else. I would definitely suggest having some sort of "loading" indicator while the table is empty and waiting for http response.
In terms of your question about the "data source", the data source of a UITableView
is simply an object that implements the UITableViewDataSource
protocol which you can read about here. Often times, you will have XCode set up a UITableViewController
object which will act as both delegate and data source to your table view. How you actually store your data is up to you. The data source protocol simply provides the methods by which a table view will "ask" for the data it needs to load.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With