I am trying to set up something where the IBAction from view controller 1 would set the ImageView image in View Controller 2's viewDidLoad using tags to differentiate between the buttons pressed…. Something like (not exact code…just hashing it out in my head):
In View Controller 1:
-(IBAction)buttonpressed:(id)sender {
if (button.tag == 1) {
ViewController2ImageView.image = [UIImage imageNamed:@"image1.png"];
}else if (button.tag == 2) {
ViewController2ImageView.image = [UIImage imageNamed:@"image2.png"];
}
In View Controller 2:
-(void)viewDidLoad {
ViewController2ImageView.image = [UIImage imageNamed:@"?.png"];
}
The issue would be how to get the info from the IBAction to pass to the second view controller and having the viewDidLoad method load the correct image.
Ive seen examples converting data to NSString and passing it that way however I was really wondering if there was a better way to go about this.
Ive been able to Google my way through putting a few apps together so far however this has had me scratching my head for a few days now.
Any help or suggested code would be helpful! Even if its just a push in the right direction.
Thanks!
When the button is pressed in viewController1, do something like this:
Then in your viewDidLoad method in viewController2 do something like this:
This code sets a string to a key in the NSUserDefaults plist (the key I used is @”viewController2SelectedImageKey” but you can use any string you like), which is referenced by viewController2 upon its viewDidLoad method and uses the string as the name of the image file.