实例成员'image'不能用于'UIImageView'

时间:2017-06-19 01:34:26

标签: 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
    }
}

如何修复此错误?这段代码会起作用还是我走向错误的方向?

2 个答案:

答案 0 :(得分:0)

实例化一个类,您需要使用初始化程序。

// 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]!
    //...
}

答案 1 :(得分:0)

UIImageView.self是类Type,UIImageView()是初始化UIImageView。