单击注释时从地图视图进行转场

Make a segue from map view when annotation is clicked

我在创建从我的地图视图到另一个视图控制器的转接时遇到问题。我希望用户单击注释并弹出另一个视图控制器。我无法在注释新闻和下一个视图控制器之间创建 segue。我将我的 segue 从地图视图命名为导航视图控制器 'annotationPress'。每当我单击地图上的注释时,我都会得到一个全黑的新视图控制器。如有任何建议,我们将不胜感激。

    func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!)
    {
//        performSegueWithIdentifier("annotationPress", sender: view)
    }


    override func performSegueWithIdentifier(identifier: String?, sender: AnyObject?) {
        println("segueing...")
        if identifier == "annotationPress"
        {

        }

    }
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "annotationPress"
        {
            println("hello")
            var vc = MapRouteViewController()

        }
    }

你不应该重写函数 performSegueWithIdentifier 只是 prepareForSegue

另外 prepareForSegue 方法你的实现是错误的(如果你试图将一些参数传递到目标视图控制器)。你需要这样的东西

let vc = segue.destinationViewController as! MapRouteViewController