First of all: I'm quite new to the whole iPhone programming world, so please forgive me any stupidities or basic errors.
What I'm trying to accomplish is to get a second view to show up with an image based on a randomly selected value from an array that's declared in the first view (which is a different class). For example, the value picked from the array is "apple", and then when the user taps a button, a second view should come up (which I already got working) showing apple.gif.
Some code to possibly make it clearer:
This method is linked to a button, so when the button is tapped, the second view comes up. This works.
Then, in Img.m I want to do the following:
This is part of the viewDidLoad method. Of course, arrayFromFirstView is considered undeclared, because it was only declared in the first view. I do want to have access to it though, I just have no idea how I'd get that.
Anybody here who could point me in the right direction? Some searching made me think it has to do with delegates, but I haven't been able to find a good article about delegates yet, so I don't know very much about that...
Thanks!
What I'm trying to accomplish is to get a second view to show up with an image based on a randomly selected value from an array that's declared in the first view (which is a different class). For example, the value picked from the array is "apple", and then when the user taps a button, a second view should come up (which I already got working) showing apple.gif.
Some code to possibly make it clearer:
Code:
-(IBAction) showImg {
Img *imgViewController = [[Img alloc] initWithNibName:@"Img" bundle:nil];
[self presentModalViewController:imgViewController animated:YES];
}
This method is linked to a button, so when the button is tapped, the second view comes up. This works.
Then, in Img.m I want to do the following:
Code:
int random = arc4random() % ([arrayFromFirstView count]);
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.gif", [arrayFromFirstView objectAtIndex:random]]];
[imageView setImage:image];
This is part of the viewDidLoad method. Of course, arrayFromFirstView is considered undeclared, because it was only declared in the first view. I do want to have access to it though, I just have no idea how I'd get that.
Anybody here who could point me in the right direction? Some searching made me think it has to do with delegates, but I haven't been able to find a good article about delegates yet, so I don't know very much about that...
Thanks!