我这里有这个代码。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
NSData* imgData=UIImagePNGRepresentation(chosenImage);
[[NSUserDefaults standardUserDefaults] setObject:imgData forKey:@"image"];
[[NSUserDefaults standardUserDefaults]synchronize];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
然后在另一个视图中我
-(void)showImage{
NSData* image=[[NSUserDefaults standardUserDefaults] objectForKey:@"image"];
UIImage* img=[UIImage imageWithData:image];
//now you can use that img image on any imageview
UIImageView *imageView = [[UIImageView alloc] initWithImage:img];
}
我正在尝试nsuserdefaults在第二个视图中加载图像,但无论我做什么它都不会在UIImageView中显示。
请不要告诉我不要使用nsuserdefaults我必须使用它
答案 0 :(得分:0)
UIImageView *imageView = [[UIImageView alloc] initWithImage:img]
强制性,不要将图像存储在NSUserDefaults