Как передать данные из аннотации карты в другой ВК - PullRequest
0 голосов
/ 27 апреля 2018

это мой первый вопрос, так что извините за ошибки. Я нашел некоторые ответы, но ничего не работает в моем коде. Прежде всего

Я сделал segue и добавил идентификатор.

это в моем 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)
        }
    }

Вот мой PlaceDetailTableViewController:

   import UIKit

class PlaceDetailTableViewController: UITableViewController {

    var selectedPlace:Place?

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

По-моему, это нечто иное, как обычная передача данных между ВК, потому что мне нужно перейти от кнопки аннотации

1 Ответ

0 голосов
/ 27 апреля 2018

Попробуйте следующим образом:

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

удалить showPlaceDetail функцию. и напечатайте selectedPlace.title перед немым методом.

...