Here is my code, which is supposed to delete the selected row. It is causing the app to crash because it claims the number of rows is not correct. I checked and it is not correct; the row in the table has been deleted, but apparently the number of rows has not been updated (the code does get hit)… how is this possible? (I have another UITableViewController with the exact code, which works). How do I fix it?
if (editingStyle == UITableViewCellEditingStyleDelete) {
// remove row from the table
SQLite *sql = [[SQLite alloc] init];
[sql deleteReadingsRow: indexPath.row];
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
Here is the code that determines the number of rows:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
SingletonListOfReadings *rShareInstance = [SingletonListOfReadings sharedInstance];
return rShareInstance.listOfReadings.count; // Return the number of rows in the section
}
I found the problem… I was relying on a singleton (SingletonListOfReadings) which was not being reset when the row was deleted in the d/b table.