我是swift和面向对象编程的新手,我试图通过点击长按下的引脚注释中的右侧附件标注按钮,将视图从包含地图的视图切换到另一个视图按。在故事板中,我在两个视图之间创建了一个segue,并为segue分配了标识符mapseg。不幸的是,在尝试了我可以通过谷歌找到的所有东西后,当我点击正确的配件标注按钮并且不知道为什么时,我无法获得segue。应用程序本身是带有三个选项卡的选项卡式应用程序。第二个选项卡的视图是包含地图的选项卡。此外,我不知道这是否与它有关,但我试图转换的视图嵌入在导航控制器中。这是我试图转换的视图的代码。
import UIKit
import MapKit
class SecondViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var MapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
self.MapView.delegate = self
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
let reuseID = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseID) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseID)
pinView!.canShowCallout = true
pinView!.animatesDrop = true
pinView!.enabled=true
let btn = UIButton(type: .DetailDisclosure)
btn.titleForState(UIControlState.Normal)
pinView!.rightCalloutAccessoryView = btn as UIView
return pinView
}
@IBAction func dropPin(sender: UILongPressGestureRecognizer) {
if sender.state == UIGestureRecognizerState.Began {
let location = sender.locationInView(self.MapView)
let locCoord = self.MapView.convertPoint(location, toCoordinateFromView: self.MapView)
let annotation = MKPointAnnotation()
annotation.coordinate = locCoord
annotation.title = "City Name"
annotation.subtitle = ""
self.MapView.removeAnnotations(MapView.annotations)
self.MapView.addAnnotation(annotation)
self.MapView.selectAnnotation(annotation, animated: true)
}
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == view.rightCalloutAccessoryView {
self.performSegueWithIdentifier("mapseg", sender: self)
}
}
}
}
答案 0 :(得分:1)
我认为您需要覆盖prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
方法。并检查是否正常工作