【问题标题】:mapKit: performing a segue after user selects an annotation markermapKit:在用户选择注释标记后执行 segue
【发布时间】:2018-08-11 15:23:18
【问题描述】:

我在执行从 mapKit 注释到另一个故事板上的另一个视图控制器的转场时遇到了问题。

我有一个带有全屏地图视图的故事板,我想对包含 PanelViewController 的另一个故事板执行转场。

使用map.addAnnotation() 向地图添加MKAnnotation 后,我使用mapView(_:didSelect:) 获取当前选定的标记。我知道我必须在这里执行 segue,但我不知道如何。

我想我有 2 个选项,但它们都不起作用:

present(PanelViewController, 动画: true, 完成: nil)

这给了我一个错误:“Cannot convert value of type 'PanelViewController.Type' to expected argument type 'UIViewController'

performSegue(withIdentifier: "showPanel", sender: view)

这会使应用程序崩溃并出现未捕获的异常错误:“Receiver (<myApp.MapViewController: 0x109200f80>) has no segue with identifier 'showPanel

当然这是真的,因为我在这个视图控制器上没有这个标识符的 segue。我不知道如何创建一个,因为它只是一个全屏 mapKit 视图,而 xcode 不允许我从 mapKit 视图中按 ctr+拖动到另一个视图控制器。

有什么想法吗?

【问题讨论】:

    标签: ios swift mapkit segue


    【解决方案1】:

    这个

     present(PanelViewController, animated: true, completion: nil)
    

    应该是实例,为 IB 中的 VC PanelViewController 创建名为 nextID 的 storyborad id

      let stoBr = UIStoryboard(name: "nameOfSB", bundle: nil)
      let next = stoBr.instantiateViewController(withIdentifier: "nextID") as! PanelViewController
    
     // here configuew next properties
    
      present(next, animated: true, completion: nil)
    

    还有这个

    performSegue(withIdentifier: "showPanel", sender: view)
    

    您从当前 VC 进行转场必须具有名为 showPanel 的转场到目标 VC

    【讨论】:

    • 嗨,谢谢...当我使用实例时,我得到一个黑屏而不是现有视图。我现在的VC确实没有名为showPanel的segue,只有全屏地图视图怎么添加?
    • 感谢您的更新,但我想我不清楚,我在我原来的问题中添加了一些屏幕截图。所以我不需要创建故事板,因为我已经有了。
    • 我没有说创建故事板,上面的行在里面有一个 VC,它的 id
    • 好吧,那种工作,但我使用多个故事板,所以你的代码给了我这个错误:故事板()不包含标识符为'PanelViewController'的视图控制器
    • 首先你应该访问它的故事板中的 VC 并将它的故事板 ID PanelViewController 作为答案中的附加照片,请参阅编辑
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多