gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:22:28 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com