1

我正在使用存储在 Core Data 中的 Person 对象填充 UITableView。每个人都有一个名字、姓氏和图像。图像是与单独的 Image 实体的关系,该实体具有称为可转换类型数据的属性。这是我存储与每个人关联的图像的地方。

我在表格中填充:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"PersonCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...
    Person *person = [self.fetchedResultsController objectAtIndexPath:indexPath];

    NSMutableString *nameString = [[NSMutableString alloc] init];

    if (person.firstName)
    {
        [nameString appendString:[NSString stringWithFormat:@"%@ ",person.firstName]];
    }
    if (person.lastName)
    {
        [nameString appendString:person.lastName];
    }

    cell.textLabel.text = nameString;

    UIImage *image = person.image.data;
    cell.imageView.image = image;

    return cell;
}

当我运行我的应用程序时,我收到错误:

:CGAffineTransformInvert:奇异矩阵。

表或数据库中的每个项目一次。

如果我注释掉这一行:

cell.imageView.image = image;

错误消失了。

有任何想法吗?这是我第一次在 Core Data 中存储二进制数据,也许它没有转换吧?

这就是我存储图像的方式:

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.person = [Person personWithImage:image inManagedObjectContext:self.context];

+ (Person *)personWithImage: (UIImage *)image inManagedObjectContext:(NSManagedObjectContext *)context
{
    Image *newImage = [NSEntityDescription insertNewObjectForEntityForName:@"Image" inManagedObjectContext:context];
    newImage.data = image;

    Person *newPerson = [NSEntityDescription insertNewObjectForEntityForName:@"Person"
                                                    inManagedObjectContext:context];
    newPerson.image = newImage;

    return newPerson;
}

谢谢,

格里

4

1 回答 1

2

好的,我很幸运地发现了这一点。我的 uitableview 使用单元格中的图像,我将全尺寸相机图像放在那里,当然遇到了一些内存问题。一旦我开始将图像大小调整为 960x640,随机 CGAffineTransformInvert 错误就消失了!

我仍然不知道为什么它首先会发生,但我想这并不重要,因为它现在已经消失了。

于 2012-07-13T22:19:23.453 回答