简体   繁体   English

在多个UIViewController之间切换时如何在UIImageView中保留图像

[英]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.

相关问题 使用UISegmentedControl在UIViewControllers之间切换 - Switching between UIViewControllers with UISegmentedControl 在UIViewController之间切换时发生什么类型的内存问题? - What type of memory issue is happening when switching between UIViewControllers? 在UINavigationController中的UIViewController之间切换 - Switching between UIViewControllers within UINavigationController 在故事板上的UIViewController之间切换 - Switching between UIViewControllers in story board 在UIViewControllers之间转换时保持UI元素的位置 - Keep UI Elements in place when transitioning between UIViewControllers 内存累积,在UIViewControllers之间切换,可以吗? - Memory Accumilation, switching between UIViewControllers, what is ok? 在UIViewController之间切换的正确设计模式是什么? - What is the right design pattern for switching between UIViewControllers? 将UIImageView切换到另一个图像时出现滞后,如何进行预分配? - Experiencing lag when switching UIImageView to another image, how to pre-allocate? 在应用之间切换时保持用户登录 - Keep user logged in when switching between apps 如何在多个UIViewControllers之间共享一个故事板场景 - How to share one storyboard scene between multiple UIViewControllers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM