Say I have 5 UIImageViews, named image1 image2 image3 image4 and image5.
And I have 5 buttons, which have their tag values set to the corresponding images that overlay them, so 1 - 5.
If button 1 is pressed, I get the tag value like so
NSNumber buttonNumber = [sender tag];
I then want to perform some methods on the corresponding image (image1). But I want to use the same method for all of the buttons.
So my question is, having retrieved the tag, how can I identify the corresponding image (with the same number after its name). The solution I have so far, which is a bit long winded, is to use a switch:
UIImageView *image;
switch (buttonTag) {
case 1:
image = imageOverButton1;
break;
case 2:
image = imageOverButton2;
break;
default:
break;
// etc
}
But this doesn't seem to be very elegant. If it were a string I could of course use
stringWithFormat:@"imageOverButton%i", buttonTag
So is there an equivalent operation for objects?
I know I could also set the button's background image to the image I want and extract the imageData from the sender but I'd rather do it the above way for various reasons. I suppose I could also add the UIImageViews to an array and extract the relevant object by using the tag.
Thanks! :D
Michael