Reputation: 29896
I need help with a problem I cant seem to solve.
I have a viewcontroller(view1) which I show by presenting it.
This view(view1) has a button on it, which when selected, presents another viewController(view 2). View 2 has a few buttons, when one is selected it opens a new viewController(view3).
Now the thing is, when a button is selected in view 3, I want to create a UIImageView which holds the image which was selected(the button which was pressed in view3) in view1 and display it.
How do I create a UIImageView with an assigned image in view1, when the action is triggered in view3?
I currently create an image but nothing is set to or shows up on view1. I wont even show the code as it is a big fail.
Thanks Thanks
Upvotes: 0
Views: 603
Reputation: 3711
From my previous answer, just replace UIImage with NSMutableDictionary in "TestAppDelegate"
UIImage *img1 = [UIImage imageNamed:@"image1.png"];
UIImage *img2 = [UIImage imageNamed:@"image2.png"];
UIImage *img3 = [UIImage imageNamed:@"image3.png"];
[imageDictionary setObject:img1 forKey:@"button1"];
[imageDictionary setObject:img2 forKey:@"button2"];
[imageDictionary setObject:img3 forKey:@"button3"];
if you want to get the particular image, just use below sample code.
TestAppDelegate *appDelegate = (TestAppDelegate*)[[UIApplication sharedApplication] delegate];
self.image = [appDelegate.imageDictionary valueForKey:@"button2"];
Upvotes: 1
Reputation: 3711
You can try with below sample code:
// TestAppDelegate.h
#import <UIKit/UIKit.h>
@interface TestAppDelegate : NSObject{
UIImage *image;
}
@property (nonatomic, retain) UIImage *image;
@end
// TestAppDelegate.m
#import "TestAppDelegate.h"
@implementation TestAppDelegate
@synthesize image;
------
------
------
@end
// TestViewController.m // sample code
#import "TestViewController.h"
#import "TestAppDelegate.h"
@implementation TestViewController
-(void)setImage{ // If you want to set an image, you can use this method. if you use like this, you can get this image from any view controller.
TestAppDelegate *appDelegate = (TestAppDelegate*)[[UIApplication sharedApplication] delegate];
appDelegate.image = self.image;
}
-(void)getImage{ // If you want to get image, you can this method.
TestAppDelegate *appDelegate = (TestAppDelegate*)[[UIApplication sharedApplication] delegate];
self.image = appDelegate.image;
}
@end
If you set a particular image in TestAppDelegate, you can access that image from any view controller using "-(void)getImage" method.
Upvotes: 0