I have a iOS app that, in a nutshell, uses a UITableView and a few buttons to change out the contents of the table. I was getting an error earlier in the development regarding the number of rows being inconsistent before and after a reloadData call but then found out what I was doing incorrectly.
Now however I’m getting a report from a tester that his iPad 1 is crashing, and looking at the stack trace I can see that the same error, as described above, is happeing. But all other iPad 2 testers seem to work correctly and they are all using the same data sets to populate the tables.
Here is how I am populating the tableview:
[tableviewController.data removeAllObjects] //Delete the old data. Tableviewcontroller is the delegate for self.tableview
[self.tableview performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[tableviewController setData:[newDataSetArray mutableCopy]]; //Copy over a new dataset array
[self.tableview performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
If anybody has any idea why this might be happening and could point it out I would really appreciate it.
EDIT:
A few more details. After hearing about this problem we had the tester delete the local copy of the app, and fetch the newest version.
Further more, he and the other testers are all running iOS 5.1.1 so as far as I can see the only inconsistency is the hardware version. But this doesn’t make sense :/
My thought would be why not just do this:
You don’t really need to clear the old one and reload, then set the new one and reload.
However, I would be careful with threading. It looks like this bit of code is being run from not-the-main-thread which means the datasource for the table might race with the setting of the data. An alternative would be to whack the whole lot on the main thread like so:
But also what I’m quite confused by is what is
tableviewControllerif the table view you’re reloading isself.tableview? Isselfnot the same astableviewController?