Reputation: 2302
I'm encountering a problem where tableView:numberOfRowsInSection:
is getting called, then a other methods are getting called that affect the underlying array, then tableView:cellForRowAtIndexPath:
gets called and crashes because the contents of the underlying array is different than when numberOfRowsInSection
was called. If the framework would call numberOfRowsInSection
right before calling cellForRowAtIndexPath
, there wouldn't be a problem.
Since I can't expect a fix in the framework in the short term, the easiest solution I'm looking at is returning a dummy cell if the underlying array doesn't contain the requested entry.
More details on how this problem occurs:
UINavigationController
.[_tableView reloadData]
.tabBarController:didSelectViewController:
method and calls popToRootViewControllerAnimated:
on the view controller being selected.Steps to repro the problem:
At step five, here is the order of the calls:
Thanks for any help you can give me.
Upvotes: 1
Views: 1230
Reputation: 394
I had a similar problem.
If you have an observer in your controller that calls reloadData
, use the viewWillAppear
method to add the observer and viewWillDisappear
to remove it.
Upvotes: 0
Reputation: 2302
This turned out to be a problem with improper calls to reloadData on the table view. I inherited this code, but I'm new enough to iOS that I didn't understand the proper usage.
The code was calling [_tableView reloadData] in both loadView and in viewWillAppear. Removing both calls solved this particular problem.
Upvotes: 1