0

次のコードでは:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                                    cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

    UILabel *label = (UILabel *)[cell viewWithTag:1];
    Person *person = [self.fetchedResultsController objectAtIndexPath:indexPath];
    label.text = person.fullName;

    UIImageView *iv = (UIImageView *)[cell viewWithTag:2];
    NSPredicate *pr = [NSPredicate predicateWithFormat:@"person == %@", person];
    Image *image = [Image MR_findFirstWithPredicate:pr inContext:person.managedObjectContext];
    iv.image = image.image ? image.image : [UIImage imageNamed:@"placeholder"];
    return cell;
}

この行

Image *image = [Image MR_findFirstWithPredicate:pr inContext:person.managedObjectContext];

不正なコンテキストを使用しています。の代わりにローカル コンテキストを使用しようとしましperson.managedObjectContextたが、それでも違法です。

何かご意見は?

4

1 に答える 1

0

なぜあなたはこれをやっているのですか?Person オブジェクトには Image 関係があるようです。使用するだけです:

imageView.image = person.image ?: [UIImage imageNamed:@"default"];

コードを読みにくくし、アプリの速度を低下させるだけのフェッチを行う必要はありません。

于 2013-09-30T15:28:11.617 に答える