gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:43:28 24 4
gpt4 key购买 nike

我在从mapKit注释到另一个 Storyboard上的其他 View Controller 执行segue时遇到问题。

我有一个带有全屏 map View 的 Storyboard,我想执行到包含 PanelViewController 的另一个 Storyboard的转场。

enter image description here enter image description here

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

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

present(PanelViewController, animated: true, completion: 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

当然这是真的,因为我在这个 View Controller 上没有使用这个标识符的segue。我不知道如何创建一个,因为它只是一个全屏 MapKit View ,并且 xcode 不允许我从 MapKit View 按住 CTR 键并拖动到另一个 View Controller 。

有什么想法吗?

最佳答案

这个

 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)

enter image description here

还有这个

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

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

enter image description here

关于ios - mapKit:在用户选择注释标记后执行segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49085606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com