0

是否可以使用字符串变量来引用UIImageView变量并更改图像?字符串变量是通过在按下按钮的标记开头添加“s”来创建的。这也是特定 UIImageView 的名称。

所以UIImageView.h 文件中声明的其中一个如下所示:

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

到目前为止,在 .m 文件中:

NSString *lastpressnum = [@(sender.tag) stringValue];
NSString *lastpressed = [NSString stringWithFormat:@"%s%@", "s", lastpressnum];
[lastpressed setImage:image];
4

1 回答 1

0

KVC 是您需要的工具。

UIImageView * theImageView = [self  valueForKey:lastpressed];
[theImageView setImage:image];
于 2013-05-04T06:05:54.350 回答