Ios 在Swift 3中过滤地图注释
我有一个MapView控制器,它包含注释以及其他数据,例如细节和图像信息。我正在尝试过滤注释及其关联数据,然后在单击callout附件控件中的DetailExposition按钮时将数据传递给DetailView控制器 我只能单独传递信息。我可以将注释标题和所有注释的数据传递给DetailView控制器。但我的目标是选择注释,单击DetailExposition按钮,传递所选注释的信息,并在DetailView控制器中查看标题、副标题、详细信息和图像名称 如有任何见解,将不胜感激 以下是我一直在研究的代码:Ios 在Swift 3中过滤地图注释,ios,swift3,segue,mapbox,Ios,Swift3,Segue,Mapbox,我有一个MapView控制器,它包含注释以及其他数据,例如细节和图像信息。我正在尝试过滤注释及其关联数据,然后在单击callout附件控件中的DetailExposition按钮时将数据传递给DetailView控制器 我只能单独传递信息。我可以将注释标题和所有注释的数据传递给DetailView控制器。但我的目标是选择注释,单击DetailExposition按钮,传递所选注释的信息,并在DetailView控制器中查看标题、副标题、详细信息和图像名称 如有任何见解,将不胜感激 以下是我一直在
class LocationAnnotation: NSObject, MGLAnnotation {
var customPointAnnotation = CustomPointAnnotation()
var location: Location?
var coordinate: CLLocationCoordinate2D
var title: String?
var subtitle: String?
var imageObj = ""
var details: String?
init(coordinate: CLLocationCoordinate2D, title: String, subtitle: String, imageObj: String, details: String, location: Location? = nil) {
self.coordinate = coordinate
self.title = title
self.subtitle = subtitle
self.imageObj = imageObj
self.details = details
}
}
更新 我最终能够通过调用CustomPointAnnotation来传递每个选定位置的数据。以下是有帮助的:
在
prepare(对于segue:sender:)
中,执行类似于controller.location=myMapView.selectedAnnotations的操作。首先如何将数据设置到mapView中?链接字典和位置的代码在哪里?我用一个解决方案更新了我的问题。感谢您的建议。在prepare(for segue:sender:)
中,执行类似于controller.location=myMapView.selectedAnnotations的操作。首先如何将数据设置到mapView中?链接字典和位置的代码在哪里?我用一个解决方案更新了我的问题。谢谢你的建议。
class MapViewController: UIViewController, MGLMapViewDelegate {
var locs = [Location]()
}
func populateMap() {
// Declare the CustomPointAnnotation and set its coordinates, title, subtitle, image.
let point = CustomPointAnnotation()
for loc in locs {
point.coordinate = CLLocationCoordinate2D(latitude: loc.latitude, longitude: loc.longitude)
point.title = loc.name
point.subtitle = loc.category
point.imageObj = loc.imageName
// Add marker to the map.
mapview.addAnnotation(point)
}
}
func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {
performSegue(withIdentifier: "moreDetail", sender: annotation.title!)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "moreDetail") {
let controller = segue.destination as! DetailsViewController
controller.location = locs
controller.data = sender as? String
}
}
func mapView(_ mapView: MGLMapView, annotation view: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {
performSegue(withIdentifier: "moreDetail", sender: view)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "moreDetail") {
let controller = segue.destination as! DetailsViewController
controller.titleShow = (sender as! CustomPointAnnotation).title
controller.subtitle = (sender as! CustomPointAnnotation).subtitle
controller.imageName = (sender as! CustomPointAnnotation).imageObj
controller.details = (sender as! CustomPointAnnotation).details
}
}