2012-10-28 15 views
1

在Xcode 4.5.1上創建應用程序,並想知道當我導航到不同視圖時,如何將當前圖像保存在指定的UIImageView中。然後,當我回到視圖它加載保存的圖像到UIImageView?

非常感謝,欣賞它:D在卸載視圖時保存UIImageView - Xcode 4.5.1

+2

這與Xcode無關...... – 2012-10-28 20:48:52

回答

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