ios - "-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object"错误

标签 ios objective-c cocoa-touch nsmutablearray

我有一个静态的 NSMutableArray,这个数组是我的 TableView 的数据源。然后我从我的 TableView 中删除了一个单元格,它崩溃了。

这里是我创建数组的地方:

static NSMutableArray *listaPiscinas;

我的代码:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {

        [listaPiscinas removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
        [TratamentoView setListaPiscinas:listaPiscinas];
        NSString *URLdeletarPiscina = [[NSString alloc] initWithFormat:@"%@app/excluir_piscina.php?cod_cliente_piscina=%@", URL_CADASTRO, [[listaPiscinas objectAtIndex:indexPath.row] objectForKey:@"cod_cliente_piscina"]];
        dataReciever = [[AsyncDownloader alloc] initWithGetAdress:URLdeletarPiscina delegate:self];

        [tableView reloadData];
    }
}

最佳答案

虽然您的变量类型为 NSMutableArray,但分配给它的对象是 NSArray,无法更改。
为了进一步帮助您向我们展示创建 listaPiscinas 的代码。

关于ios - "-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21193615/

相关文章:

ios - 能否获取iBeacon的扫描响应

ios - react native 错误 - react-native-xcode.sh : line 45: react-native: command not found Command/bin/sh failed with exit code 127

objective-c - UICollectionViewCell 填充

ios - 数组中的多个项目给出符合编码的错误

ios - 更改 UITableViewCell 中 UILabel 的背景颜色

android - delphi xe6 目标多字节代码页中不存在 Unicode 字符的映射

ios - 增加 UIScrollView 橡皮筋阻力

ios - 如何删除不再需要的 View Controller ?

ios - 如果你使用 set RootViewController 是否会从内存中删除之前的 RootViewController?

ios - 搜索区域在 swift MKMapView 中获取坐标