Objective c 目标c在表视图中滑动以删除

Objective c 目标c在表视图中滑动以删除,objective-c,swipe,Objective C,Swipe,我有两个自定义单元格。我正在尝试使用“滑动到删除”按钮。 但当我点击删除按钮时它崩溃了 代码如下: - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyle

我有两个自定义单元格。我正在尝试使用“滑动到删除”按钮。 但当我点击删除按钮时它崩溃了

代码如下:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        if (indexPath.row % 2 == 0) {
            [_arrayCars removeObjectAtIndex:indexPath.row/2];
            [_tblCars deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }else{
            [_arrayGirls removeObjectAtIndex:(indexPath.row - 1)/2];
            [_tblCars deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }
        withRowAnimation:UITableViewRowAnimationFade];
    } else {
        NSLog(@"Unhandled editing style! %d", editingStyle);
    }
}
以下是我得到的:

    ExampleXib[6957:281486] -[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x7feea851bc60
    2017-01-23 19:31:49.798 ExampleXib[6957:281486] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x7feea851bc60'

_arrayCars是不可变数组,不能删除其中的对象。让它可变,它应该是好的!
\u arrayCars
是否声明为
NSArray
?如果是,则声明(并执行正确的alloc/init)为
NSMutableArray
。如果它已经声明为
NSMutableArray
,请检查您在何处创建它,如果需要,请执行
[[NSMutableArray alloc]initWithArray:tempArray]
,因为
tempArray
是一个
NSArray
,而您确实执行了
\u arrayCars=tempArray,可能会导致问题。thanx,它与“initWithArray”配合使用效果良好!