0

NSJsonSerilization用来获取UITableView单元格中的 JSON 数据。我已将数组声明为 .NSMutableArray但我仍然得到

-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object error 

每当我尝试删除单元格时,应用程序就会崩溃。

cell.nameLabel.text = [[jsonResults objectAtIndex:indexPath.row] objectForKey:@"FromProviderName"];

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [jsonResults removeObjectAtIndex:indexPath.row];
    [jsonTable reloadData];
}

我试图查找之前回答的解决方案,我正在做同样的事情。谢谢!

4

1 回答 1

0

我希望您在获取请求结束时需要名为“mutableCopy”的函数。

jsonResults = (NSMutableArray*)[[cdc.managedObjectContext executeFetchRequest:fetchRequest error:&error] mutableCopy];

根据您的评论编辑:

jsonResults = (NSMutableArray*)[[NSJSONSerialization JSONObjectWithData:data options:nil error:nil] mutableCopy];
于 2013-09-12T09:47:29.920 回答