我正在尝试像这样删除一个 UITableViewCell:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self._tableViewItems beginUpdates];
[self._tableViewItems deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self._tableViewItems endUpdates];
[[AppDelegate appDelegate].managedObjectContext deleteObject:[_arraySortedItems objectAtIndex:indexPath.row]];
NSError *error = nil;
[[AppDelegate appDelegate].managedObjectContext save:&error];
}
[self getItems];
}
这里是getItems:
-(void)getItems
{
_arrayAllItems = NULL;
_arrayAllItems = [[NSMutableArray alloc]initWithArray:[[AppDelegate appDelegate]getItems]];
_arraySortedItems = NULL;
_arraySortedItems = [[NSMutableArray alloc]initWithArray:_arrayAllItems];
[_tableViewItems reloadData];
[_tableViewItems setNeedsLayout];
但是这段代码在 [self._tableViewItems endUpdates] 处失败了;除了这个异常(exception):
Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-2903.23/UITableView.m:1330
在网上搜索,但没有任何解决方案可以帮助我。
谢谢你的帮助
最佳答案
您可以简单地创建一个主从项目来获取它的演示引用。它已经在那里可用。或者你可以试试这个。
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
如果有效,请告诉我。
关于ios - 删除 UITableViewCell 引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21310874/