ios - 实例成员 'image' 不能用于类型 'UIImageView'

标签 ios swift

var imageView = UIImageView.self

let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: UUID(uuidString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D")!, identifier: "Estimotes")

let images = [
    53219:  UIImage(named:"White Glyph 2"),
    59317:  UIImage(named:"White Glyph 3"),
    17068: UIImage(named:"White Glyph 4")
]


func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
    let knownBeacons = beacons.filter{ $0.proximity != CLProximity.unknown }
    if (knownBeacons.count > 0) {
        let closestBeacon = knownBeacons[0] as CLBeacon
        self.imageView.image = self.images[closestBeacon.minor.intValue] // error gets thrown on this line
    }
}

如何修复此错误?这段代码可以工作还是我走错了方向?

最佳答案

实例化一个类,需要使用初始化器。

// var imageView = UIImageView.self
var imageView = UIImageView()

//...

func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
    //...
        //self.imageView.image = self.images[closestBeacon.minor.intValue] 
        self.imageView.image = self.images[closestBeacon.minor.intValue]!
    //...
}

关于ios - 实例成员 'image' 不能用于类型 'UIImageView',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44621142/

相关文章:

ios - swift/Core Data - 为数据模型创建 "dummy"NSManagedObject ID(无需托管对象即可测试事物)

iOS 应用程序在每月付费订阅后免费使用 1 个月

swift - 使用 XLPagerTabStrip 时出现问题

ios - 点击时如何在 UICollectionViewCell 中制作此动画?

ios - 无法使用 segue 将数据传递到第二个 Controller

ios - 不同的单元格取决于单元格文本

ios - 无法生成证书和配置文件

ios - 如何检查文件是否存在使用 swift,从 objective c 重写

ios - 使用 NSXMLParser 解析 xml 属性

ios - DismissViewController swift