[英]TableView deletion error
我从以下代码中收到以下错误:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[self.tableView reloadData];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[[FavouritesController sharedController] removeFavouriteAtIndex:indexPath.row];
[self.tableView reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleNone) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
请您告诉我如何解决?
***-[[UITableView _endCellAnimationsWithContext:],/ SourceCache / UIKit / UIKit-1448.89 / UITableView.m:995 2011-04-19 21:30:17.854 APPNAME [546:707]中的断言失败***由于以下原因终止了应用程序未捕获的异常'NSInternalInconsistencyException',原因:'无效更新:第0节中的行数无效。更新(4)之后现有节中包含的行数必须等于更新前该节中包含的行数(4),加上或减去从该部分插入或删除的行数(插入0,删除1)。
您可能需要以下代码:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[[FavouritesController sharedController] removeFavouriteAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleNone) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
在更改表格之前,请更改模型。
因此,请尝试:
[[FavouritesController sharedController] removeFavouriteAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
您可能不需要所有这些重载,除非模型更改的不仅仅只是一个索引路径。 行删除本身会进行一些重新加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.