我试图为iPhone5编写一个非常基本的Xcode(第5版)项目应用程序,它将照片库中的图像加载到启动UIImageView
中的UIViewController
并且在其他视图控制器面板之间切换时,将该图像保留在UIImageView
中(或将其返回)。我遇到的问题是当我从其他UIViewController
窗口返回到我的UIImageView
主视图控制器时,之前显示的已加载图像已经消失,我最终不得不将其重新加载到UIImageView
。在从其他UIImageView
窗口返回后,如何使图像保留在UIViewController
中?
实施档案......
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (IBAction)btnClick:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
modBuffer = info[UIImagePickerControllerEditedImage];
self.imageView.image = modBuffer;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
标头文件......
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
UIImage* modBuffer;
}
@property (strong, nonatomic) IBOutlet UIImageView* imageView;
- (IBAction)btnClicked:(id)sender;
答案 0 :(得分:0)
我认为您需要为UIImage (nonatomic,retain)
创建属性,然后您应该尝试这样做。