[英]How to keep an image in a UIImageView when switching between multiple UIViewControllers
I'm trying to write an extremely basic Xcode (ver. 5) project application for the iPhone5 that loads an image from the photo library into an UIImageView
in the start up UIViewController
and keeps that image in the UIImageView
(or returns it) when switching between other view controller panels. 我试着写一个非常基本的Xcode(第五版)对iPhone5的工程应用加载从照片库中的图像转换成一个
UIImageView
在启动UIViewController
,并保持在该图像UIImageView
(或返回吧)切换时在其他视图控制器面板之间。 The problem I am having is that when I return from other UIViewController
windows to the main view controller with my UIImageView
, the loaded image that was previously displayed is gone and I end up having to reload it into the UIImageView
. 我遇到的问题是,当我使用
UIImageView
从其他UIViewController
窗口返回到主视图控制器时,以前显示的已加载图像消失了,最终我不得不将其重新加载到UIImageView
。 How can I make this behave where the image remains in the UIImageView
after I return from other UIViewController
windows? 从其他
UIViewController
窗口返回后,如何使图像保持在UIImageView
?
Implementation File... 实施文件...
#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
Header file... 头文件...
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
UIImage* modBuffer;
}
@property (strong, nonatomic) IBOutlet UIImageView* imageView;
- (IBAction)btnClicked:(id)sender;
我认为您需要为UIImage (nonatomic,retain)
属性UIImage (nonatomic,retain)
,然后您应该尝试这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.