Invalid update: invalid number of rows in section

本秂侑毒 提交于 2019-11-30 09:28:19

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.

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!