我正在开发一个应用程序,它从网站中获取某个用户名的照片,并在UITable中显示该用户名,然后单击用户名时会显示此用户的照片,再单击照片名称时会显示全屏照片。
我的问题是,我使用NSData从互联网上获取照片。我是否需要将数据保存到CoreData中?当按下用户名时,它会创建NSData并从互联网下载照片并在UITable上显示它们。这需要时间。
什么是好的方法?如何将这些图像保存到CoreData中?
我正在使用这种方法:
NSData *imageData=[flickr dataForPhotoID:firstPhoto.id fromFarm:firstPhoto.farm
onServer:firstPhoto.server withSecret:firstPhoto.secret inFormat:
FlickrFetcherPhotoFormatSquare];
这里是 dataForPhotoID 方法的定义
- (NSData *)dataForPhotoID:(NSString *)photoID fromFarm:(NSString *)farm
onServer:(NSString *)server withSecret:(NSString *)secret
inFormat:(FlickrFetcherPhotoFormat)format {
#if TEST_HIGH_NETWORK_LATENCY
sleep(1);
#endif
NSString *formatString;
switch (format) {
case FlickrFetcherPhotoFormatSquare: formatString = @"s"; break;
case FlickrFetcherPhotoFormatLarge: formatString = @"b"; break;
}
NSString *photoURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_%@.jpg", farm, server, photoID, secret, formatString];
NSURL *url = [NSURL URLWithString:photoURLString];
return [NSData dataWithContentsOfURL:url];
}
NSData
。如果你有一个UIImage
,你如何在不使用像UIImagePNGRepresentation
这样生成NSData
对象的情况下将PNG存储到数据库中? - Rob