ios - 为什么这个 UIImageView 认为它是一个 UIView?

标签 ios uiview uiimageview viewwithtag

<分区>

在 Storyboard的 View Controller 中,我有一个简单的 View ,它有一个带有标签 0 的 subview 图像和一个带有标签 1 的 subview 标签。

我正在尝试获取这样的图像:

UIImageView *myImage = (UIImageView*)[myView viewWithTag:0];

但是当我这样做的时候:

myImage.highlighted = YES;

我明白了:

-[UIView setHighlighted:]: unrecognized selector sent to instance

在storyboard中明明是一个UIImageView。为什么这个转换不起作用?

最佳答案

因为 [myView viewWithTag:0] 这也是主视图的标签号

解决方案:

  • 为您的 UIImageView 对象添加一个标签,比如 100
  • 现在以 (UIImageView*)[myView viewWithTag:100] 访问它

关于ios - 为什么这个 UIImageView 认为它是一个 UIView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23921594/

相关文章:

iphone - setEnabled 不适用于 UIButton

ios - 什么时候必须在 iOS AutoLayout 中使用优先级?

ios - 如何检测 UICollectionView 的所有可见单元格已加载

ios - +(void) 初始化线程安全

ios - 将文本标签添加到绘制的形状

ios - 切换 View 会使应用程序崩溃

swift - 读取 sender.tag 时将 UIImageView 与选择器@objc C 函数一起使用时 Swift 出错

ios - UIImageView Aspect Fill 不填充 View

ios - iOS 中的 subview 动画一次一个

ios - Swift 中的 ScrollView 和 View 层次结构