mapKit:在用户选择注释标记后执行segue

问题描述 投票:0回答:1

我在执行mapKit注释中的segue到另一个故事板上的其他视图控制器时遇到问题。

我有一个带有全屏地图视图的故事板,我想对包含PanelViewController的其他故事板执行segue。

enter image description here enter image description here

使用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个回答
0
投票

这个

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

应该是实例,为IB中的VC qazxsw poi创建名为nextID的故事板id

PanelViewController

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)

还有这个

enter image description here

您执行segue的当前VC必须具有名为showPanel的segue到目标VC

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

© www.soinside.com 2019 - 2024. All rights reserved.