卸载视图时保存 UIImageView - Xcode 4.5.1
Posted
技术标签:
【中文标题】卸载视图时保存 UIImageView - Xcode 4.5.1【英文标题】:Save UIImageView When Unload A View - Xcode 4.5.1 【发布时间】:2012-10-28 20:47:44 【问题描述】:在 Xcode 4.5.1 上创建应用程序并想知道当我导航到不同的视图时如何将当前图像保存在指定的 UIImageView 中。然后当我返回视图时,它会将保存的图像加载到 UIImageView 中?非常感谢,不胜感激:D
【问题讨论】:
这与Xcode无关... 【参考方案1】:我在下面发布的代码涉及将 uiimage 传递给第二个视图控制器。它还包括每个控制器上的按钮,用于在两者之间来回移动。当您在视图之间切换时,保存的图像将保留在 uiimageview 中。
SecondView.h
#import <UIKit/UIKit.h>
@interface SecondView : UIViewController
IBOutlet UIImageView *yourphotoview;
UIImage *yourimage;
@property (retain, nonatomic) UIImage *yourimage;
- (IBAction)back;
@end
SecondView.m
#import "ViewController.h"
#import "SecondView.h"
@interface SecondView ()
@end
@implementation SecondView
@synthesize yourimage;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
// Custom initialization
return self;
- (void)viewDidLoad
yourphotoview.image = image;
[super viewDidLoad];
// Do any additional setup after loading the view.
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (IBAction)back
[self dismissViewControllerAnimated:YES completion:NULL];
- (void)dealloc
[image release];
[super dealloc];
@end
ViewController.h
#import <UIKit/UIKit.h>
#import "SecondView.h"
@interface ViewController : UIViewController
IBOutlet UISlider *compression;
IBOutlet UISwitch *smurferderp;
SecondView *SecondViewdata;
@property (retain, nonatomic) SecondView *SecondViewdata;
@property (retain, nonatomic) IBOutlet UIImageView *theimage;
- (IBAction)switchview:(id)sender;
@end
ViewController.m
#import "ViewController.h"
#import "SecondView.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize SecondViewdata, theimage;
- (IBAction)switchview:(id)sender
SecondView *secondview = [self.storyboard instantiateViewControllerWithIdentifier:@"rr"];
self.SecondViewdata = secondview;
SecondViewdata.yourimage = theimage.image;
[self presentViewController: secondview animated:YES completion:NULL];
- (void)dealloc
[theimage release];
[super dealloc];
@end
【讨论】:
以上是关于卸载视图时保存 UIImageView - Xcode 4.5.1的主要内容,如果未能解决你的问题,请参考以下文章
当单元格具有 UIImageView 子视图时,UITableView 经历断断续续的滚动