DocAsh59
DocAsh59

Reputation: 400

Save UIImageView When Unload A View - Xcode 4.5.1

Creating an app on Xcode 4.5.1 and wondering how do i save the current image in the specified UIImageView when i navigate to a different view. Then when i return to the View it loads up the saved image into the UIImageView?

Thank a lot, appreciate it :D

Upvotes: 1

Views: 210

Answers (1)

maelswarm
maelswarm

Reputation: 1070

The code I've posted below involves passing a uiimage to a second view controller. It also includes a button on each controller to move back and forth between the two. The saved image will stay in the uiimageview when you switch to and from the views.

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

Upvotes: 1

Related Questions