我正在使用包含图像的自定义点注释。我在 var 注释行中收到几个错误,例如“计算属性必须具有显式类型”和“具有 getter/setter 的变量不能具有初始值”。如果我修复了另一个就会弹出。有谁知道如何在 Swift 3 中实现这一点?
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
let eventPageViewController:EventPageViewController = storyboard?.instantiateViewController(withIdentifier: "EventPage") as! EventPageViewController
var annotation = view.annotation as? CustomPointAnnotation{
eventPageViewController.photo = annotation?.imageName
}
self.present(eventPageViewController, animated: true, completion: nil)
}
这是自定义点类:
class CustomPointAnnotation: MKPointAnnotation {
var imageName: UIImage!
}
最佳答案
这是对我有用的解决方案:
let annotation1 = view.annotation as! CustomPointAnnotation
eventPageViewController.photo = annotation1.imageName
关于ios - 在 Swift 中使用自定义点注释时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42073846/