Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is it possible to use a string variable to refer to a UIImageView variable and change the image? The string variable is created by adding an "s" to the start of the tag of the button pressed. This is also the name of a specific UIImageView.

So one of the UIImageView declared in the .h file looks like this:

@property (retain, nonatomic) IBOutlet UIImageView *s11;

And in the .m file so far:

NSString *lastpressnum = [@(sender.tag) stringValue];
NSString *lastpressed = [NSString stringWithFormat:@"%s%@", "s", lastpressnum];
[lastpressed setImage:image];
share|improve this question

1 Answer

KVC is the tool you need.

UIImageView * theImageView = [self  valueForKey:lastpressed];
[theImageView setImage:image];
share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.