【发布时间】:2011-07-19 03:27:32
【问题描述】:
当我尝试删除单元格时,我崩溃了......
Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UITableView.m:976
2011-07-19 08:55:53.575 MyTable[477:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 1. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted).'
下面是我的代码
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = [aContentArray objectAtIndex:indexPath.row];
cell.detailTextLabel.text =[aDetailTextArray objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"home-picture.jpg"];
return cell;
}
(void)viewDidLoad { [超级viewDidLoad];
// 取消注释以下行以在 此视图控制器的导航栏。 self.navigationItem.rightBarButtonItem = self.editButtonItem;
aContentArray = [[NSMutableArray arrayWithObjects:@"iPhone",@"Android",@"Blackberry",@"Symbian",nil]retain];
aDetailTextArray = [[NSMutableArray arrayWithObjects:@"iPhone 是 来自 Apple Inc”,@“Android 来自 Google,它是开放的 source",@"Blackberry 来自 RIM Research In Motion",@"使用 Symbian 来自诺基亚",nil]retain];}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[self.aDetailTextArray removeObjectAtIndex:indexPath.row];
[self.aContentArray removeObjectAtIndex:indexPath.row];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
[tableView reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
请帮帮我,谢谢
【问题讨论】: