核心数据和Grand Central调度内部不一致

Tia*_*oso 1 core-data grand-central-dispatch ios

我正在使用iOS 5开发iOS应用程序.

我无法使用宏中央调度来填充GMGridViewCell的视图.

问题不在于GridCell本身,而是在GCD中访问数据.

这是我的代码:

- (GMGridViewCell *)GMGridView:(GMGridView *)gridView cellForItemAtIndex:(NSInteger)index
{
    //NSLog(@"Creating view indx %d", index);

    CGSize size = [self sizeForItemsInGMGridView:gridView];

    GMGridViewCell *cell = [gridView dequeueReusableCell];

    if (!cell) 
    {
        cell = [[GMGridViewCell alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    }

    [[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];

    dispatch_queue_t fillCellQueue = dispatch_queue_create("Cell fetch queue", NULL);
    dispatch_async(fillCellQueue, ^{
        SearchGridViewCell *cellView = [UIView loadFromNib:@"SearchGridViewCell" owner:self];
        Item *item = [self.foundItems objectAtIndex:index];

        cellView.itemImageView.image = [UIImage imageWithData:item.image.thumb];

        cellView.itemNameLabel.text  = item.name; 

        cellView.brandImageView.image = [UIImage imageWithData:item.group3.image.thumb];

        Attribute *itemAttribute = [item.attributes objectAtIndex:0];
        cellView.attributeLabel.text  = [itemAttribute.name stringByAppendingFormat:@": "];
        [cellView.attributeLabel sizeToFit];

        cellView.itemAttributeValueLabel.text = itemAttribute.value;
        [cellView.itemAttributeValueLabel sizeToFit];

        dispatch_sync(dispatch_get_main_queue(), ^{
            [cell addSubview:cellView];
        });
    });
    dispatch_release(fillCellQueue);

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

运行应用程序时,我收到以下错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'statement is still active'
*** First throw call stack:
(0x1a1f052 0x35b3d0a 0x11cde0a 0x11cd58d 0x11f689f 0x11ec955 0x11d7df4 0x11f6418 0x11f3b62 0x11f3a57 0x11f316b 0x11f2f97 0x11f2b75 0x11f29f2 0x1236e10 0x51de7 0x44ab445 0x44acecf 0x44acd28 0x44ac4af 0x91442b24 0x914446fe)
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

编辑更多信息,

抛出异常的第一行:

cellView.itemImageView.image = [UIImage imageWithData:item.image.thumb];
Run Code Online (Sandbox Code Playgroud)

而且我认为这个问题来自GCD,因为当我在没有GCD的情况下运行它时,它运行正常.但是网格的滚动有点迟钝,这就是为什么我要为它添加GCD.

chr*_*ris 6

我相信问题在于self.foundItems,我猜测是NSFetchRequest另一个线程中的请求的结果. NSManagedObject不能在线程之间传递.您必须在要使用它的同一个线程中获取对象.