Ios 将数据从地图注释传递到局部视图控制器SWIFT 3
我在试图弄清楚如何从地图视图控制器中的pin地图注释显示详图视图控制器时遇到了很多麻烦。当我单击“详细信息披露”按钮时,它会将我带到“详细信息视图”控制器,但不会传递任何数据。这只是我在故事板上做的基本布局。 在注释中。但在我的详细视图控制器中,我有超过15种不同的数据 如何显示它,以便在单击地图注释时,它会将我带到其各自的详图控制器,其中包含所有数据,而不仅仅是注释类中的数据 任何帮助都将不胜感激 这是我的MapViewController的一部分Ios 将数据从地图注释传递到局部视图控制器SWIFT 3,ios,swift,mkmapview,swift3,mkannotation,Ios,Swift,Mkmapview,Swift3,Mkannotation,我在试图弄清楚如何从地图视图控制器中的pin地图注释显示详图视图控制器时遇到了很多麻烦。当我单击“详细信息披露”按钮时,它会将我带到“详细信息视图”控制器,但不会传递任何数据。这只是我在故事板上做的基本布局。 在注释中。但在我的详细视图控制器中,我有超过15种不同的数据 如何显示它,以便在单击地图注释时,它会将我带到其各自的详图控制器,其中包含所有数据,而不仅仅是注释类中的数据 任何帮助都将不胜感激 这是我的MapViewController的一部分 // 1 @objc(mapView:vie
// 1
@objc(mapView:viewForAnnotation:) func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? Annotations {
let reuseID = "pin"
var view: MKPinAnnotationView
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseID)
as? MKPinAnnotationView { // 2
dequeuedView.annotation = annotation
view = dequeuedView
} else {
// 3
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseID)
view.canShowCallout = true
view.isUserInteractionEnabled = true
view.calloutOffset = CGPoint(x: -5, y: 5)
view.rightCalloutAccessoryView = UIButton.init(type: .detailDisclosure) as UIButton
}
return view
}
return nil
}
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == view.rightCalloutAccessoryView {
print(view.annotation?.title)
performSegue(withIdentifier: "moreDetail", sender: self)
}
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "moreDetail") {
// pass data to next view
let destViewController:PancakeHouseViewController = segue.destination as! PancakeHouseViewController
destViewController.viaSegue = (sender as! MKAnnotationView)
}
}
class PancakeHouseViewController: UITableViewController, MKMapViewDelegate {
var viaSegue = MKAnnotationView()
@IBOutlet weak var addressLabel: UILabel!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var detailsLabel: UILabel!
@IBOutlet weak var priceGuideLabel: UILabel!
并且my.viaSegue与名为PancakeHouseViewController的详图视图控制器连接
// 1
@objc(mapView:viewForAnnotation:) func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? Annotations {
let reuseID = "pin"
var view: MKPinAnnotationView
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseID)
as? MKPinAnnotationView { // 2
dequeuedView.annotation = annotation
view = dequeuedView
} else {
// 3
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseID)
view.canShowCallout = true
view.isUserInteractionEnabled = true
view.calloutOffset = CGPoint(x: -5, y: 5)
view.rightCalloutAccessoryView = UIButton.init(type: .detailDisclosure) as UIButton
}
return view
}
return nil
}
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == view.rightCalloutAccessoryView {
print(view.annotation?.title)
performSegue(withIdentifier: "moreDetail", sender: self)
}
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "moreDetail") {
// pass data to next view
let destViewController:PancakeHouseViewController = segue.destination as! PancakeHouseViewController
destViewController.viaSegue = (sender as! MKAnnotationView)
}
}
class PancakeHouseViewController: UITableViewController, MKMapViewDelegate {
var viaSegue = MKAnnotationView()
@IBOutlet weak var addressLabel: UILabel!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var detailsLabel: UILabel!
@IBOutlet weak var priceGuideLabel: UILabel!
这是“注释”类
}在pancakeHouseVC类中添加一个新字典,您将使用它来传递数据
class PancakeHouseViewController: UITableViewController, MKMapViewDelegate {
var viaSegue = MKAnnotationView()
var dataDict:[String:String]
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "moreDetail") {
// pass data to next view
let destViewController:PancakeHouseViewController = segue.destination as! PancakeHouseViewController
destViewController.viaSegue = (sender as! MKAnnotationView)
// set your data here in dataDict
destViewController. dataDict = ["name":"add name"]
}
}
在pancakeHouseVC类中添加一个新字典,您将使用它来传递数据
class PancakeHouseViewController: UITableViewController, MKMapViewDelegate {
var viaSegue = MKAnnotationView()
var dataDict:[String:String]
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "moreDetail") {
// pass data to next view
let destViewController:PancakeHouseViewController = segue.destination as! PancakeHouseViewController
destViewController.viaSegue = (sender as! MKAnnotationView)
// set your data here in dataDict
destViewController. dataDict = ["name":"add name"]
}
}
你可以在PrepareForegue中传递数据是的,但我不知道该怎么做。viaSegue。当我尝试传入.namelab而不是.viaSegue时,它说它不是MKAnnotationView类型。我该如何解决这个问题?您可以在PrepareForSegue中传递数据是的,但我不知道如何处理。viaSegue。当我尝试传入.namelab而不是.viaSegue时,它说它不是MKAnnotationView类型。我将如何解决这个问题?