ios - 我的 MKMapAnnotation 的扩展工作了 1/3 次,有什么办法可以修复它,让它一直工作吗?
问题描述
所以我正在制作一个需要在 swift 中使用 MKMapAnnotations 的应用程序,为此我使用了一个扩展程序,该扩展程序将每个注释自定义为具有一个按钮、一个自定义图像和一个背景。所有这些都在第一次尝试时有效,但是,对于第二次和第三次尝试,它显示默认注释,没有按钮或注释功能,但在第四次尝试时它有效(之后每三次尝试)。为此,我登录和退出我的应用程序并重新加载 MapView。这是什么原因/我该如何解决?这是扩展名。
这是我第一次在这里发帖,所以任何有关如何帮助您帮助我的建议也将不胜感激:)
extension MapViewController: MKMapViewDelegate {
// 1
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
// 2
guard let annotation = annotation as? Artwork else { return nil }
// 3
let identifier = "marker"
var view: MKMarkerAnnotationView
// 4
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
as? MKMarkerAnnotationView {
dequeuedView.annotation = annotation
view = dequeuedView
view.glyphImage = UIImage(named: "TiffinIcon")
view.markerTintColor = UIColor.orange
}
else {
// 5
view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.canShowCallout = true
view.calloutOffset = CGPoint(x: -5, y: 5)
view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
view.glyphImage = UIImage(named: "TiffinIcon")
view.markerTintColor = UIColor.orange
//view.tag = counter
let btn = UIButton(type: .detailDisclosure)
btn.setImage(UIImage(named: "TiffinIcon"), for: .normal)
view.rightCalloutAccessoryView = btn
//view.tag = counter
print("counter tagged:\(counter)")
}
return view
}
//Button Clicked Function
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if let annotation = view.annotation as? Artwork {
print("This is the \(annotation.tag)")
newTag = annotation.tag
performSegue(withIdentifier: "successfulSegue", sender: self)
}
}
}
解决方案
推荐阅读
- sql - 通过 DACPAC 部署数据库时,一些更新触发器正在添加额外的行 EXECUTE sp_settriggerorder
- c# - 多个摄像机 - 固定:随机房间
- sql-server - 最小化预登台数据库事务日志增长
- arm - QEMU-system-arm 安装缺少 sabrelite 机器
- git - docker 主机密钥验证失败
- wordpress - 带有 URL 参数的 WordPress REST API 自定义端点
- html - CSS - 调整 div 的大小会影响相邻的 div
- sql - 将表连接到复杂查询
- frama-c - 如何证明这个 assigns 子句,第 2 部分?
- django - {% debug %} Django 模板标签不工作