【发布时间】:2016-11-30 09:45:52
【问题描述】:
大家好,我正在尝试将注释上的图钉替换为自定义图像。
我的 image.cassette 列表中已经有图像,将显示 1X 2X 3X 等,但是当我尝试调用该图像时,我的代码中出现错误,Xcode 尝试修复我的语法但最终抛出它是错误的
下面列出的我的代码覆盖函数
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else {
return nil
}
let annotationIdentifier = "AnnotationIdentifier"
var annotationView: MKAnnotationView?
if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) {
annotationView = dequeuedAnnotationView
annotationView?.annotation = annotation
}
else {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
}
if let annotationView = annotationView {
annotationView.canShowCallout = true
annotationView.image = UIImage(named: "House")
}
return annotationView
}
现在Xcode 在代码 annotationView.image = UIImage(named: "House") 中发现错误,它要求插入 ",",最终结果如下所示
annotationView.image = UIImage(named: "#imageLiteral(resourceName: ",House,")")
Xcode 将显示错误使用未解析的标识符“House”
【问题讨论】:
-
错误说明了什么?
-
使用未解析的标识符“House”
标签: ios swift3 mkpinannotationview