這是我的代碼,它應該刪除選定的行。它導致應用程序崩潰,因爲它聲稱行數不正確。我查了一下,這是不正確的;表中的行已被刪除,但顯然行數沒有更新(代碼確實被打)......這怎麼可能? (我有另一個UITableViewController與確切的代碼,它的工作原理)。我如何解決它?UITableView:爲什麼刪除後「行數」沒有被更新?
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];
}
這裏是確定的行數的代碼:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
SingletonListOfReadings *rShareInstance = [SingletonListOfReadings sharedInstance];
return rShareInstance.listOfReadings.count; // Return the number of rows in the section
}