-1

this is my first question so sorry for mistakes. I found some answers but nothing work in my code. First of all

I made segue and add identifier.

this is in my MainMapViewController:

  func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
        guard let annotation = mapView.selectedAnnotations.first else {return}
        annotationPlace = annotation as? Place
        self.performSegue(withIdentifier: "showDetail", sender: self)
    }

    func showPlaceDetail(segue: UIStoryboardSegue){
        let viewController = segue.destination as? PlaceDetailTableViewController
        viewController?.selectedPlace = annotationPlace
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "showDetail" {
            showPlaceDetail(segue: segue)
        }
    }

Here is my PlaceDetailTableViewController:

   import UIKit

class PlaceDetailTableViewController: UITableViewController {

    var selectedPlace:Place?

    override func viewDidLoad() {
        super.viewDidLoad()
        dump(selectedPlace as Any)
        print(selectedPlace?.title)
    }
}

In my opinion it is something different like normal passing data between VC's because i have to make segue from annotation button

1 Answers1

0

Try This way:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showDetail" {
        if let toViewController = segue.destination as? PlaceDetailTableViewController {
           toViewController.selectedPlace = annotationPlace
        }
    }
}

remove showPlaceDetail function. and print selectedPlace.title before dumb method.

MRizwan33
  • 2,723
  • 6
  • 31
  • 42