That's probably not a good way to work. What you want is an array of imageViews. Then you just need a numeric index, and you can go through the array of imageViews hiding everything that doesn't have the chosen index.
But how do you get an array of imageViews? See How to make IBOutlets out of an array of objects? It explains how to use IBOutletCollection.
If you have a separate button for each view, put those into an IBOutletCollection too. That way you can have something like this:
- (IBAction) imageButtonPressed:(id) sender;
{
// The sender is the button that was just pressed.
NSUInteger chosenIndex = [[self imageButtons] objectAtIndex:sender];
for (NSUInteger imageIndex = 0; imageIndex < [[self imageViews] count]; imageIndex++)
{
// Hide all views other than the one associated with the pressed button.
if (imageIndex != chosenIndex)
{
[[[self imageViews] objectAtIndex:imageIndex] setHidden:YES];
}
else
{
[[[self imageViews] objectAtIndex:imageIndex] setHidden:NO];
}
}
}
If you really, really need to associate the string image1
with an imageView, you can construct an NSDictionary
associating your controls with unique string identifiers for later lookup. NSDictionary is powerful, but I'm drawing a blank on reasons why this would be needed.
NSMutableDictionary *viewLookup;
[viewLookup setObject:[[self imageViews] objectAtIndex:0] forKey:@"image0"];
[viewLookup setObject:[[self imageViews] objectAtIndex:1] forKey:@"image1"];
[viewLookup setObject:[[self imageViews] objectAtIndex:2] forKey:@"image2"];
[viewLookup setObject:[[self imageButtons] objectAtIndex:0] forKey:@"button0"];
// ...
// Can now look up views by name.
// ...
NSString *viewName = @"image1";
UIView *viewFound = [viewLookup objectForKey:viewName];
[viewFound doSomething];