I have a UITableView with some cells. When a cell is tapped, I set a string variable called Index to the index of the cell that was tapped. I have verified that this is working with an NSLog of Index from my UIImageView’s controller. Now, what I’m trying to do is set the image of a UIImageView to an image corresponding to the cell tapped (i.e. a different image for each cell). The way I’m trying to do this (it doesn’t work) is with this code in my UIImageView’s controller’s ViewDidLoad method:
if ([[TableViewController alloc] Index] isEqualToString:@"0"]) {
Display.image = [UIImage imageNamed:@"0.jpg"];
}
‘Display’ is the name of my UIImageView.
Is this code correct? If it is, where should I put it so that when I tap the first cell my UIImageView initialises with the image called “0.jpg”?
Is your image view controller already visible (loaded) on the same screen as your table view, or are you pushing a new image view controller for each cell tap on the table view? This makes a huge difference in how to approach this. If you are doing the former, using viewDidLoad won’t work because the view is already loaded. You’ll have to write a method to change the image, like:
If you’re pushing a new image view each time, then you’ll want to make an instance variable in the image view class and put this in your table view didSelectRow… method:
It might be helpful to post more of your code so we can see the situation with how the views are loaded.