PDA

View Full Version : Call to tableview reloadData skips over




khartley
May 16, 2011, 02:19 PM
I have to wait for a return from a call to a web service before I can populate my data source with the correct data (an array of images). In the method that I have created in the viewController I pass in that array, getting the datasource populated and ready for its display. After populating the datasource, I call [tableView reloadData] - but in the debugger, it's like skipping over a comment - nothing ever happens. Does this behavior indicate to any of you something that I should check? It seems like I don't have something quite right (obviously), but I can't think of what!



aaronbrethorst
May 17, 2011, 10:19 PM
I have to wait for a return from a call to a web service before I can populate my data source with the correct data (an array of images). In the method that I have created in the viewController I pass in that array, getting the datasource populated and ready for its display. After populating the datasource, I call [tableView reloadData] - but in the debugger, it's like skipping over a comment - nothing ever happens. Does this behavior indicate to any of you something that I should check? It seems like I don't have something quite right (obviously), but I can't think of what!

Let's start with the stuff that I always forget to do!


Is your table view actually initialized?
Is your view controller set to be the delegate and dataSource of your table view?


Usually, I add an NSMutableArray instance variable to my view controller; call it tableItems, or something. Make sure you initialize it in your view controllers -init method (whichever you happen to be using). Return the -count of the mutable array from -tableView:numberOfRowsInSection:, and do the similar, proper thing in -tableView:cellForRowAtIndexPath:

When your async network operation returns, do something like this:


[tableItems addObjectsFromArray:myNSArray];
[self.tableView reloadData];