I've been searching for a really long time but I found no answer for my question(s).
In my app I have a segmented control with two buttons. When I toggle between those buttons I do:
- Show a loading screen as a subview
- do an url request to get the content to show in my tableview
- fill my dataArray for my TableView with the new data
- call reload data
- remove loading screen subview.
In most cases everything works fine, BUT..
Sometimes, really not often, the table view "crashes", after this 5 steps. It means. The view only show one or two cells. And when I scroll to top or bottom I only scroll into white. In my current solution I can't reproduce this error on my iPhone(IOS6), only in simulator(IOS7). I think it has something to do with scrolling while changing the data of the table view. It only occurs while scrolling and pressing the segmented control button shortly after started scrolling, but only sometimes. But it could have another reason for sure..
My Question is, what could cause the table view to layout wrong (only displaying some cells correctly and scrolling into white), any Idea? And how can I recover/redraw the whole tableview after this happened? Please help..
I read a lot about [tableview beginUpdates],[tableview endUpdates] and insertRows, but I think this is not the right solution in this case. Or tell me if I'm wrong.
Here is the main code snipped for steps 2-4. If another part of code could help, maybe the cellForRowIndexPath, let me know.
NSMutableArray *newResults = [[NSMutableArray alloc] initWithArray:[self getResultsForRequest:url]];
[resultsLock lock];
results = newResults; //results is the data source for my tableView
[resultsLock unlock];
[self.tableView reloadData];
Thanks to all responders.