最后我只是请求与图像URL和接收我抢了图像的URL将其设置为我的对象的图像属性的对象之后的对象。简单
NSURL * imageURL; UIImage * selectedImage;
for (Employee *employee in _employees){
imageURL = [NSURL URLWithString:employee.imageURL];
selectedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
// Delete any existing image.
NSManagedObject *oldImage = employee.image;
if (oldImage != nil) {
[employee.managedObjectContext deleteObject:oldImage];
}
// Create an image object for the new image.
NSManagedObject *image = [NSEntityDescription insertNewObjectForEntityForName:@"Image" inManagedObjectContext:employee.managedObjectContext];
employee.image = image;
// Set the image for the image managed object.
[image setValue:selectedImage forKey:@"image"];
// Create a thumbnail version of the image for the recipe object.
CGSize size = selectedImage.size;
CGFloat ratio = 0;
if (size.width > size.height) {
ratio = 100.0/size.width;
} else {
ratio = 100.0/size.height;
}
CGRect rect = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height);
UIGraphicsBeginImageContext(rect.size);
[selectedImage drawInRect:rect];
employee.thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
你的目标部署是10.7和iOS 5? – user170317 2011-12-17 09:19:27
这个项目的iOS5,但它也将有助于4.0 – 2011-12-17 20:52:53