【问题标题】:XCode - Referring to a UIImageView variable through another string variable?XCode - 通过另一个字符串变量引用 UIImageView 变量?
【发布时间】:2013-05-04 05:13:21
【问题描述】:

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

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

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

到目前为止的.m文件中:

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

【问题讨论】:

    标签: ios objective-c xcode uiimageview nsstring


    【解决方案1】:

    KVC 是您需要的工具。

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

    【讨论】:

      猜你喜欢
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      • 2016-10-29
      相关资源
      最近更新 更多