单击MapView注释时,Swift Parse到另一个视图控制器

时间:2018-02-20 19:48:38

标签: ios swift xcode parse-platform mkmapview

我目前有一个UIMapView,其中有不同的注释,用于地图上用户的不同位置。单击注释时,我试图切换到相应的用户配置文件。这是我设置注释的代码:

 let query = PFQuery(className: "location")

    query.findObjectsInBackground { (objects, error) in


        if let brandsLocation = objects {

            for object in brandsLocation {

                if let brandLocation = object as? PFObject {

                    let annotation = MKPointAnnotation()

                    let annotationPoint = object["geoPoint"] as! PFGeoPoint

                    annotation.coordinate = CLLocationCoordinate2DMake(annotationPoint.latitude, annotationPoint.longitude)

                    annotation.title = brandLocation["annotationTitle"] as? String

                    annotation.subtitle = brandLocation["annotationSubtitle"] as? String

                    self.map.addAnnotation(annotation)




                }

            }

        }
    }

这是我认为segue应该发生的地方,但是由于某些原因它没有做任何事情。

       // When user taps on the disclosure button you can perform a segue 
       to navigate to another view controller
    func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, 
 calloutAccessoryControlTapped control: UIControl) {

        if control == view.rightCalloutAccessoryView{

            performSegue(withIdentifier: "goToUserProfile", sender: view)

            print(view.annotation?.title) // annotation's title

            print(view.annotation?.subtitle) // annotation's subttitle


            //Perform a segue here to navigate to another viewcontroller
            // On tapping the disclosure button you will get here
        }
    }


    // Here we add disclosure button inside annotation window
    func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {

        print("viewForannotation")
        if annotation is MKUserLocation {
            //return nil
            return nil
        }

        let reuseId = "pin"
        var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView

        if pinView == nil {
            //println("Pinview was nil")
            pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
            pinView!.canShowCallout = true
            pinView!.animatesDrop = true
        }

        let button = UIButton(type: UIButtonType.detailDisclosure) as UIButton // button with info sign in it

        pinView?.rightCalloutAccessoryView = button


        return pinView
    }

我想在单击或双击注释时发生segue,然后在发送特定用户名信息时对新视图控制器执行segue。我很确定我能够发送用户信息,但我只需要弄清楚如何使segue发生。任何帮助深表感谢!谢谢

更新问题可能是我的CalloutAccessory未显示。当我点击我的应用中的图钉时,请查看此屏幕截图:

MapView Annotation Clicked

0 个答案:

没有答案