【发布时间】:2018-01-10 23:18:02
【问题描述】:
这是我在 util 文件中的功能。它抱怨“'UIViewController' 类型的值没有成员 'mapView'”
func removeSpecificCustomAnnotation(annotationArray: [CustomPointAnnotation], annotationIdToRemove: String, viewController: UIViewController) {
for annotation in annotationArray {
if let ID = annotation.locationID, ID == annotationIdToRemove {
viewController.mapView.removeAnnotation(annotation)
}
}
}
我不能再回答了。我在这里发布我的工作内容
这是工作功能。我想删除地图上的注释
- 在我的 viewController.swift 中
- 声明 var mapView = MKMapView()
- 显示所有注释的功能 -> 我不放这里
- 现在,我想删除上面显示的注释之一
- 我有注释的 ID(您需要使用自定义注释来执行此操作)
- 注解ID由函数根据经纬度生成
- 现在,我需要找到具有该 ID 的注释并将其删除
-
我得到了地图上的所有注释
让注解 = mapView.annotations.filter { $0 !== self.mapView.userLocation }
-
循环注释数组,然后删除我需要的那个
for annotation in annotations { let getLat: CLLocationDegrees = annotation.coordinate.latitude let getLon: CLLocationDegrees = annotation.coordinate.longitude let cllocation: CLLocation = CLLocation(latitude: getLat, longitude: getLon) let locationID = Utils.generateLocationID(newcllocation: cllocation, existingCllocationToEdit: nil) if locationID == annotationIdToRemove { self.mapView.removeAnnotation(annotation) } }
【问题讨论】:
-
导入框架。
-
@ElTomato 什么框架?这不是框架问题。这是试图访问
UIViewController上不存在的属性。