Couple of points for clarity...
- As indicated by @k20, it is not that
tableView:cellForRowAtIndexPath:
is called too early, but that you need to better manage your download data once your asynchronous process / method has completed.
tableView:cellForRowAtIndexPath:
is a UITableView
data source method, not a delegate method. It is worth mentioning this pedantic detail because it may help you or others better understand the code you are writing. ;)
The table view method calls are what they are - as I understand it, all table view methods are called in order, each time a UITableViewController
is init
or awakeFromNib
. Those that you must override (tableView:numberOfRowsInSection:
& tableView:cellForRowAtIndexPath:
), and those that you choose to override will still execute in that same order.
Therefore a more appropriate title for your question might be... "How to update a UITableView with data from a download on an asynchronous thread."
Again @k20 is pointing you to the correct solution. Have you attempting placing these two lines of code...
[self.tableView reloadData];
[_rcRefresh endRefreshing];
within your async call, instead of back in the main queue?
It may be that your code as written is executing like this...
- Prepare local variables for
dispatch_q_t
;
- Commence download process;
- reload data for table view;
- end the refresh
[_rcRefresh endRefreshing]
;
- depending on time it takes, then finish download process;
Where you obviously would like to execute like this...
- Prepare local variables for
dispatch_q_t
;
- Commence download process;
- depending on time it takes, finish download process;
- reload data for table view;
- end the refresh
[_rcRefresh endRefreshing]
;
Try my suggestion and let me know how you go. Hope that helps.