Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 尝试对NSMutableArray重新排序时出现运行时异常_Ios_Objective C_Core Data_Nsmutablearray - Fatal编程技术网

Ios 尝试对NSMutableArray重新排序时出现运行时异常

Ios 尝试对NSMutableArray重新排序时出现运行时异常,ios,objective-c,core-data,nsmutablearray,Ios,Objective C,Core Data,Nsmutablearray,我有一个UITableViewController,它显示存储在核心数据中的用户定义收藏夹列表。加载表视图时,托管对象被放置在可变数组中。为了构造可变数组,我使用以下静态方法(在单独的类中): 在我的表视图中,我需要允许用户对行重新排序。我已经验证了我最喜欢的托管对象的可变数组是否已完成,但是,当我尝试删除给定索引处的对象时,会在运行时引发异常([\PFArray removeObjectAtIndex:]:发送到实例的无法识别的选择器)。以下是导致异常的代码: - (void)tableVie

我有一个UITableViewController,它显示存储在核心数据中的用户定义收藏夹列表。加载表视图时,托管对象被放置在可变数组中。为了构造可变数组,我使用以下静态方法(在单独的类中):

在我的表视图中,我需要允许用户对行重新排序。我已经验证了我最喜欢的托管对象的可变数组是否已完成,但是,当我尝试删除给定索引处的对象时,会在运行时引发异常([\PFArray removeObjectAtIndex:]:发送到实例的无法识别的选择器)。以下是导致异常的代码:

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
    [self setEditing:YES animated:YES];        
    NSInteger rowIndex = fromIndexPath.row;
    Favorite *fave = [allFavoriteObjects objectAtIndex:rowIndex];

    [allFavoriteObjects removeObjectAtIndex:rowIndex]; // exception thrown here
    [allFavoriteObjects insertObject:fave atIndex:toIndexPath.row];
}

有什么建议吗?谢谢

执行此操作时使用辅助NSMUTABLEARY,因为类中使用了
所有FavoriteObjects
,并且tableview中的各种方法都可以访问它们。

执行此操作时使用辅助NSMUTABLEARY,因为类中使用了
所有FavoriteObjects
,以及tableview中的各种方法访问它们。

NSManagedObjectContext的executeFetchRequest可能返回一个不可变的数组。试试这个

return [[context executeFetchRequest:fetchReq error:&err] mutableCopy];

NSManagedObjectContext的executeFetchRequest可能正在返回一个不可变的数组。试试这个

return [[context executeFetchRequest:fetchReq error:&err] mutableCopy];
而不是

return (NSMutableArray*)[context executeFetchRequest:fetchReq error:&err];
试用

return [[context executeFetchRequest:fetchReq error:&err] mutableCopy];
而不是

return (NSMutableArray*)[context executeFetchRequest:fetchReq error:&err];
试用

return [[context executeFetchRequest:fetchReq error:&err] mutableCopy];

(NSMutableArray*)
强制转换不是必需的。使用mutableCopy时是否需要强制转换?确定。我把它取下来。这是没有必要的。因为我们可以确定,id实际上是一个NSMutableArray。
(NSMutableArray*)
强制转换不是必需的。使用mutableCopy时强制转换是必需的吗?确定。我把它取下来。这是没有必要的。因为我们可以确定,id实际上是一个NSMutableArray。