Reputation: 2337
I am stuck in a really weird issue, What em doing is calling NSURLConnection sendAsynchronousRequest
in which i reload tableView and it does it without any issue. This scenario works fine while em standing on the same ViewController while request response is received. The issue arises when I call sendAsynchronousRequest
and move from that ViewController and then come back to it before the request gives the response. This time the TableView reloadData
gets called but doesn't do anything on the View. I call the reloadData in this dispatch_async(dispatch_get_main_queue(), ^{});
for it to run on mainThread
.
Any help in this regard would be great.
Edit 1:
Here's what i have gotten far till now.. when i start the NSURLConnection asyncRequest it keeps the reference to the tableView and array that it has at that current time.. But when i navigate off from that view and then come back the view is reinitialized so the tableView and array has new references. So when the asyncRequest calls tableView ReloadData, it calls reload for the older referenced tableView rather than the one that is now visible hence not reloading the tableView… hope now you can help.
Upvotes: 0
Views: 137
Reputation: 2225
Rather than reloading tableview on main thread, try to reload it once you get data and the data is parsed. Switching between views may cause your tableview to reload before the data comes from server resulting blank tableview and this is caused due to calling some methods on main thread.
EDIT: Try to initialize tableview in viewdidload only and array just after you get response from server and before loading data in it.
Upvotes: 2