2011-04-19 30 views
0

我从下面的代码获得以下错误:的TableView删除错误

- (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删除)。'

回答

0
你改变你的表之前

更改模型。

所以尝试:

[[FavouritesController sharedController] removeFavouriteAtIndex:indexPath.row]; 
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

你可能,除非模型的变化不仅仅是一个索引路径并不需要所有这些重载。行删除自己进行一些重新加载。

0

你可能想验证码:

- (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 
    } 
}