2011-09-08 66 views
0

我在删除tableview中的单元格时出现问题,当我按下删除按钮时,程序会崩溃。删除表格中的单元格查看

这里是我的代码吧:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the managed object at the given index path 
     sect = [listArray objectAtIndex:indexPath.row]; 
     [sect removeObjectAtIndex:indexPath.row]; 

     // Update Event objects array and table view 
     [listArray removeObjectAtIndex:indexPath.row]; 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; 
     tableView.editing = YES; 

     } 
} 
+1

与什么碰撞? EXC_BAD_ACCESS或SIGABRT数组索引超出范围或什么? – 0x8badf00d

+0

发布您的崩溃日志的输出。 – WrightsCS

+0

thx,问题解决了 – John2

回答

-1

完全删除以下:

sect = [listArray objectAtIndex:indexPath.row]; 
[sect removeObjectAtIndex:indexPath.row]; 

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; 

只需拨打[listArray removeObjectAtIndex:indexPath.row];然后调用reloadData刷新UITableView