【问题标题】:Make a segue from map view when annotation is clicked单击注释时从地图视图中进行转场
【发布时间】:2015-05-04 20:09:33
【问题描述】:

我在创建从我的地图视图到另一个视图控制器的转场时遇到问题。我希望用户单击注释并弹出另一个视图控制器。我在创建注释新闻和下一个视图控制器之间的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()

        }
    }

【问题讨论】:

    标签: ios iphone swift mapkit mapkitannotation


    【解决方案1】:

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

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

    let vc = segue.destinationViewController as! MapRouteViewController
    

    【讨论】:

    • 我认为你不应该创建从 mapview 到 detailviewcontroller 的 segue(这是否有效?),而是从包含 mapview 的 viewcontroller 到 detailviewcontroller!
    猜你喜欢
    • 1970-01-01
    • 2013-10-17
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 2018-05-10
    相关资源
    最近更新 更多