2017-11-27 3 views
0

Wie kann ich MKAnnotationView auf die angegebene Annotation platzieren, nachdem ich die Tabellenansichtszelle ausgewählt habe? Muss ich irgendwie Funktion mapView (_: didSelect :) innerhalb didSelectRowAtIndexPath der Tabellenansicht aufrufen? Hier ist meine Didselectrow Func. Ich habe versucht mit map.selectAnnotation innerhalb didselectrow, aber gibt nil zurück.Open Map AnnotationView von selectedRow in der TabelleView

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 


     let pin = filteredDetails[indexPath.row].coordinate 

     let latDelta: CLLocationDegrees = 0.009 
     let lonDelta: CLLocationDegrees = 0.009 

     let span = MKCoordinateSpanMake(latDelta, lonDelta) 
     let location = CLLocationCoordinate2DMake(pin.latitude, pin.longitude) 
     let region = MKCoordinateRegionMake(location, span) 

     mapView.setRegion(region, animated: true) 

     // mapView.selectAnnotation(customXibView as! MKAnnotation, animated: true) 

     tableView.isHidden = true 


     } 

Und das ist meine Karte didselect func.

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) { 

     let meridianAnnotation = view.annotation as! Details 

     let customXibView = Bundle.main.loadNibNamed("CustomCalloutVIew", owner: self, options: nil)?[0] as! CustomAnnotationClass! 

     customXibView?.address.text = meridianAnnotation.address 
     customXibView?.phone.text = meridianAnnotation.phone 

     let calloutFrame = view.frame 
     customXibView?.frame = CGRect(x: (calloutFrame.size.width)-178.0, y: (calloutFrame.size.height)-220, width: 315, height: 166) 


     customXibView?.blurOverlay.effect = UIBlurEffect(style: .light) 
     customXibView?.layer.masksToBounds = true 


     let shadowView = UIView(frame: CGRect(x: (calloutFrame.size.width)-178.0, y: (calloutFrame.size.height)-220, width: 315, height: 154)) 
     shadowView.translatesAutoresizingMaskIntoConstraints = false 
     shadowView.backgroundColor = UIColor.clear 
     shadowView.layer.borderWidth = 7.0 
     shadowView.layer.borderColor = UIColor.lightGray.cgColor 
     shadowView.alpha = 1.0 
     shadowView.layer.cornerRadius = 10.0 
     shadowView.layer.shadowOffset = CGSize(width: 4.0, height: 4.0) 
     shadowView.layer.shadowOpacity = 1.0 
     shadowView.layer.shadowRadius = 13.0 

     view.insertSubview(shadowView, at: 0) 

     view.addSubview(customXibView!) 

     mapView.setCenter((view.annotation?.coordinate)!, animated: true) 


    } 
+0

mapView.selectAnnotation suchen funktioniert nur, wenn Sie Annotation-Objekt übergeben, die bereits in mapview –

+0

gut hinzugefügt wird, sind meine Objekte alle bereits auf der Karte hinzugefügt, wenn ich auf Zelle drücken Sie zentriert Karte auf verwandte Annotation, alles, was ich will ist, zusätzlich für Callout-Ansicht zu Pop-up, als ob ich es ausgewählt .... – NikolaS

Antwort

0
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 


     let pin = filteredDetails[indexPath.row].coordinate 

     let latDelta: CLLocationDegrees = 0.009 
     let lonDelta: CLLocationDegrees = 0.009 

     let span = MKCoordinateSpanMake(latDelta, lonDelta) 
     let location = CLLocationCoordinate2DMake(pin.latitude, pin.longitude) 
     let region = MKCoordinateRegionMake(location, span) 

     mapView.setRegion(region, animated: true) 

     mapView.selectAnnotation(filteredDetails[indexPath.row], animated: true) 

     tableView.isHidden = true 


     } 
0

In Ihrem didSelectRowAtIndexPath, Sie passieren customXibView anstelle des

Sie haben für Annotation zu suchen, die mit diesem Tableview

Sobald Sie es finden, können Sie es sagen, um es auszuwählen unter Verwendung:

mapView.selectAnnotation

Sie können u se https://stackoverflow.com/a/39980302/4601900 Antwort Anmerkung aus MapView

Verwandte Themen