【发布时间】:2023-04-01 04:40:01
【问题描述】:
我构建了一个简单的 mac 数据输入工具,用于 iPhone 应用程序。我最近添加了缩略图,我使用简单的绑定通过 Image Well 添加了该缩略图。它是一种可转换的数据类型,似乎工作正常。
但是,iPhone 应用程序不会显示图像。该属性不为空,但我无法显示图像。以下是针对 cellForRowAtIndexPath
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSManagedObject *entity = nil;
if ([self.searchDisplayController isActive])
entity = [[self filteredListContent] objectAtIndex:[indexPath row]];
else
entity = [fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [entity valueForKey:@"name"];
//cell.imageview.image = [UIImage imageNamed:@"ImageB.jpeg"]; //works fine
cell.imageView.image = [entity valueForKey:@"thumbnail"];//no error, but no file
return cell;
我认为问题出在可转换(我使用的是默认的 NSKeyedUnarchiveFromData),或者我如何调用缩略图。我是新手,非常感谢任何帮助。
【问题讨论】:
-
thumbnail是什么类型的?是NSData吗?如果是这样,您将需要从该数据创建 UIImage。 -
属性类型是可转换的(我的出发点是来自苹果的 Core Data Recipes 示例,它也使用了可转换的缩略图)。它使用自定义值转换器 (ImageToDataTransformer),由于 UIImage 的原因,该转换器无法在数据输入应用程序上编译。
标签: iphone core-data imageview nsmanagedobject