コアデータストアから画像をプルするiCarouselの基本的な実装があります。予想どおり、大量の画像をロードすると、メモリ関連のクラッシュが発生します。問題は、コアデータオブジェクトにNSURLの敬意がないため、AsyncImageViewライブラリを使用する方法がわからないことです。このメモリの問題を管理する別の方法を知っている人はいますか?
これが私のiCarouselviewForItemAtIndexです
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
JournalEntry *journalEntry = (JournalEntry *)[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]];
if (view == nil)
{
view = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240.0f, 240.0f)] autorelease];
view.contentMode = UIViewContentModeScaleAspectFit;
}
[((UIImageView *)view) setImage:[journalEntry.image valueForKey:@"image"]];
NSLog(@"%i", index);
return view;
}
参考までに、iPhoneCoreDataRecipesサンプルコードから直接コアデータストアに画像を追加するためのコードを示します。
@implementation ImageToDataTransformer
+ (BOOL)allowsReverseTransformation {
return YES;
}
+ (Class)transformedValueClass {
return [NSData class];
}
- (id)transformedValue:(id)value {
NSData *data = UIImagePNGRepresentation(value);
return data;
}
- (id)reverseTransformedValue:(id)value {
UIImage *uiImage = [[UIImage alloc] initWithData:value];
return [uiImage autorelease];
}
@end