Ios NSManagedObject自定义子类中的UIImage是否在核心数据模型中存储缩略图并避免快速滚动?
简而言之:有哪些方法可以将缩略图添加到Ios NSManagedObject自定义子类中的UIImage是否在核心数据模型中存储缩略图并避免快速滚动?,ios,objective-c,uiimageview,uiimage,uicollectionview,Ios,Objective C,Uiimageview,Uiimage,Uicollectionview,简而言之:有哪些方法可以将缩略图添加到NSManagedObject自定义子类中,而不必将缩略图存储在核心数据模型中,也不必避免在UICollectionView中快速滚动 我有一个带有单元格的UICollectionView,每个单元格都有一个UIImageView。我从UICollectionViewController获取对象。在collectionView:cellForItemAtIndexPath:方法中,我使用NSManagedObject中的图像分配UIImageView。我最初
NSManagedObject
自定义子类中,而不必将缩略图存储在核心数据模型中,也不必避免在UICollectionView
中快速滚动
我有一个带有单元格的UICollectionView
,每个单元格都有一个UIImageView
。我从UICollectionViewController
获取对象。在collectionView:cellForItemAtIndexPath:
方法中,我使用NSManagedObject
中的图像分配UIImageView
。我最初是这样做的:
imageView.image = [UIImage imageWithData:managedObject.image];
但是当我滚动UICollectionView
时,它是不稳定的(图像太大)
我尝试在collectionView:cellForItemAtIndexPath:
中缩小它们的比例,但没有任何帮助。最后我决定:
//in collectionView:cellForItemAtIndexPath: in ViewController
IimageView.image = managedObject.thumbnail;
//in NSMangedObjects custom subclass .m
...
@property (nonatomic) UIImage *thumbnail;
//in NSMangedObjects custom subclass .m
...
-(id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext:(NSManagedObjectContext *)context
{
self = [super initWithEntity:entity insertIntoManagedObjectContext:context];
if (self) {
UIImage *image = [UIImage imageWithData:self.image];
CGSize sacleSize = CGSizeMake(190, 190);
UIGraphicsBeginImageContextWithOptions(sacleSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, sacleSize.width, sacleSize.height)];
UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
thumbnail = smallImage;
}
return self;
}
myUICollectionView
中的单元格为(80 x 80)。有了以上内容,我的收藏视图可以很好地滚动。就性能而言,在NSManagedObject
中创建缩略图更好,还是应该在其他地方创建缩略图(但不是在collectionView:cellForItemAtIndexPath:
方法中)