I am trying an array item as a the object name.
I have 5 UIImageViews set up:
@interface miniTestViewController : UIViewController {
NSArray *array;
IBOutlet UIImageView *sun;
IBOutlet UIImageView *moon;
IBOutlet UIImageView *rain;
IBOutlet UIImageView *snow;
IBOutlet UIImageView *hail;
}
-(IBAction)fadeChosenImage:(id)sender;
My plist contains an array of image names: sun, moon, rain, snow, hail
In the .m VDL stub, this plist is read into an NSArray *array.
A UIButton tag selects the object at index:
-(IBAction)fadeChosenImage:(id)sender{
NSString *image = [[NSString alloc] init];
image= nil;
switch ([sender tag]) {
case 0:
image = [array objectAtIndex:[sender tag]];
break;
case 1:
image = [array objectAtIndex:[sender tag]];
break;
case 2:
image = [array objectAtIndex:[sender tag]];
break;
case 3:
image = [array objectAtIndex:[sender tag]];
break;
case 4:
image = [array objectAtIndex:[sender tag]];
break;
default:
break;
}
I need to use the NSString as the UIImageView object name, like this:
[[array objectAtIndex:[sender tag]] setAlpha:0];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:6.0];
[[array objectAtIndex:[sender tag]] setAlpha:1];
but so far objectAtIndex returns a NSString which does not respond to the setAlpha message.
Is it possible to convert/wrap/cast/use the NSString to the object name of the UIImageVIew
Thank you very much for any help.
It would be much easier to save your image view objects into the array directly, rather than trying to retrieve them using a string.
If you want to find objects using a string as a key, store them in a dictionary.
Hoever, in your case, you have a numeric index. Just save the UIImageView objects directly into your array. That does not duplicate the objects – it just saves references to them in your array.