【发布时间】:2020-09-02 08:22:00
【问题描述】:
我想使用CreateDetailsViewController 中的按钮创建注释以将其添加到MapViewController。
当我在 MapView 上的 viewDidLoad 中键入以下代码时,它可以正常工作。但我不知道如何从一个屏幕到另一个屏幕实现它。
我对编程很陌生,所以请在回答时考虑这一点。谢谢!
//Button I want to create the annotation with in `CreateDetailsViewControllwer` :
@IBAction func publishButtonPressed(_ sender: UIButton) {
performSegue(withIdentifier: "goToMap", sender: self)
func prepare (for segue: UIStoryboardSegue, sender: Any?) {
let MapVC = segue.destination as! MapViewController
var london = MKPointAnnotation()
london.title = "London"
london.coordinate = CLLocationCoordinate2DMake(51.508530, -0.076132)
MapVC.mapView.addAnnotation(london)
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard annotation is MKPointAnnotation else {return nil}
let identifier = "Annotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView!.canShowCallout = true
} else {
annotationView!.annotation = annotation
}
return annotationView
}
【问题讨论】:
标签: ios swift xcode annotations mapkit