在 Xcode 4.5.1 上创建应用程序并想知道当我导航到不同的视图时如何将当前图像保存在指定的 UIImageView 中。然后当我返回视图时,它会将保存的图像加载到 UIImageView 中?
非常感谢,不胜感激 :D
问问题
205 次
1 回答
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
于 2013-04-28T04:38:29.767 回答