在swift中将注释从一个视图传递到另一个视图
我想将注释从ViewController传递到ARViewController,并将其显示在地图上。当我按下segue按钮时,我收到一条Nil错误消息:(以下是我在ViewController中的内容在swift中将注释从一个视图传递到另一个视图,swift,Swift,我想将注释从ViewController传递到ARViewController,并将其显示在地图上。当我按下segue按钮时,我收到一条Nil错误消息:(以下是我在ViewController中的内容 var startPt = POIs(coordinate: CLLocationCoordinate2D(latitude: Double("")!, longitude: Double("")! )) func mapView(_ mapView: MKMapView, annotation
var startPt = POIs(coordinate: CLLocationCoordinate2D(latitude: Double("")!, longitude: Double("")! ))
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {
let storyboard = UIStoryboard(name: "Main", bundle:nil)
let viewController = storyboard.instantiateViewController(withIdentifier : "ARV")
self.present(viewController, animated: true)
//location.mapItem().openInMaps(launchOptions: launchOptions)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//guard let ViewController = segue.destination as? ARViewController,
if segue.identifier == "ARV"{
let vc = segue.destination as! ARViewController
vc.dest = startPt
}
}
var dest = POIs(coordinate: CLLocationCoordinate2D(latitude: Double("")!, longitude: Double("")! ))
override func viewDidLoad() {
super.viewDidLoad()
//show the user's current location
mapView.userTrackingMode = .follow
mapView.delegate = self as? MKMapViewDelegate
mapView.addAnnotation(dest)
}
这就是我在ARViewController中看到的
var startPt = POIs(coordinate: CLLocationCoordinate2D(latitude: Double("")!, longitude: Double("")! ))
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {
let storyboard = UIStoryboard(name: "Main", bundle:nil)
let viewController = storyboard.instantiateViewController(withIdentifier : "ARV")
self.present(viewController, animated: true)
//location.mapItem().openInMaps(launchOptions: launchOptions)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//guard let ViewController = segue.destination as? ARViewController,
if segue.identifier == "ARV"{
let vc = segue.destination as! ARViewController
vc.dest = startPt
}
}
var dest = POIs(coordinate: CLLocationCoordinate2D(latitude: Double("")!, longitude: Double("")! ))
override func viewDidLoad() {
super.viewDidLoad()
//show the user's current location
mapView.userTrackingMode = .follow
mapView.delegate = self as? MKMapViewDelegate
mapView.addAnnotation(dest)
}
您正在手动显示目标视图控制器,而不是执行序列,因此不会调用
prepare(for:sender:)
您有两个选择:
calloutAccessoryControlTapped
中设置dest
属性,例如:
let viewController = storyboard.instantiateViewController(withIdentifier : "ARV") as! ARViewController
viewController.dest = ...
或ARV
),例如
如果您这样做,prepare(for:sender:)
将被调用。FWIW,我看不到您在哪里设置startPt