Swift MapKit:从annotationView将数据解析到下一个VC

时间:2017-02-10 16:20:59

标签: ios swift

当用户点击rightCalloutAccessoryView时,有没有办法将信息数组解析到下一个VC?

假设我有这组信息需要解析:

[name: "XXX",gender: "YYY",lat: 11.1111,lon: 22.2222]

在下一个VC中,我们将以“个人资料页面”的方式显示这些信息。到目前为止,我的实施是这样的:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

        let reuseIdentifier = "pin"
        var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier)

        if annotationView == nil {
            annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
            annotationView?.canShowCallout = true
            annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
        } else {
            annotationView?.annotation = annotation
        }

        annotationView?.image = UIImage(named: "PersonIcon")

        return annotationView
}

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
        if control == view.rightCalloutAccessoryView {
            viewActivity()
        }
}

func viewActivity() {
        let controller = storyboard?.instantiateViewController(withIdentifier: "ActivityView") as! ActivityViewController
        controller.parsedInfo = /*parsedInfo*/
        navigationController?.pushViewController(controller, animated: true)
}

编辑:

viewDidLoad中的addAnnotation代码:

FIRHelperClient.sharedInstance.getLocationsForActivities(ref) { (results, error) in
        if let error = error {
            print(error.localizedDescription)
        } else {

            for result in results! {
                guard let lat = result.lat, let lon = result.lon, let activity = result.searchActivities else {
                    print("locationForActivities did not return lat or lon")
                    return
                }

                let annotation = MKPointAnnotation()
                annotation.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lon)
                annotation.title = activity
                self.mapView.addAnnotation(annotation)
            }
        }
    }

0 个答案:

没有答案