Invalid update: invalid number of rows in section

后端 未结 2 927
滥情空心
滥情空心 2020-12-31 20:04

I am working on a project using Microsoft Azure services. In that while deleting a row I am getting this error:

Terminating app due to uncaught          


        
相关标签:
2条回答
  • 2020-12-31 20:55

    The important thing is that you need to use either

    [self.medicationsTableView reloadData];
    

    or

    [self.medicationsTableView deleteRowsAtIndexPaths:@[cellIndexPath] withRowAnimation:UITableViewRowAnimationRight];
    

    The reason being, when the tableview's reload data is called the row which is removed from data source is deleted and after that when the delete row api is called for the same index path(where the row is already deleted causes the issue)

    Also just before deleting the row from the table delete the object from the data source (self.fetchedResultsController1) and call

    [self.medicationsTableView deleteRowsAtIndexPaths:@[cellIndexPath] withRowAnimation:UITableViewRowAnimationRight];
    

    and after the above row's deletion animation is completed than you can call(but it is not required)

    [self.medicationsTableView reloadData];
    
    0 讨论(0)
  • 2020-12-31 20:57

    In - (void)swipeableTableViewCell: didTriggerRightUtilityButtonWithIndex:

    You need to remove either

    [self.medicationsTableView reloadData]; 
    

    or

    [self.medicationsTableView deleteRowsAtIndexPaths:@[cellIndexPath] withRowAnimation:UITableViewRowAnimationRight];
    

    Because on first line when reloadData get called it's reload the tableview with new datasource and again calling deleteRowsAtIndexPaths tried to delete a rows which already removed by calling reloadData earlier.

    0 讨论(0)
提交回复
热议问题