Swift 故事板 - 使用 calloutaccessorycontroltapped 显示按钮在 MapView 中创建一个 segue

Swift storyboard - Creating a segue in MapView using calloutaccessorycontroltapped disclosure button

在我的 MapView 中,我有几个 MKAnnotation 引脚,每个引脚都配置了 viewFor,以显示右侧带有披露 "I" 按钮的小弹出窗口。

现在我正在尝试找到一种方法来通过点击弹出窗口中的披露 "I" 按钮来创建一个 segue - 我看到这可以通过

来完成
func mapView(... calloutAccessoryControlTapped control: UIControl)

但是,因为storyboard中当然没有显示MKAnnotation pin,所以我不知道如何使用control-drag的方法来创建segue并获取相应的segue ID。

我的解决方法 - 我基本上实例化了我希望继续的另一个视图控制器,并在按下 "I" 按钮时切换到那个新视图

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
    let settingVC = self.storyboard?.instantiateViewController(withIdentifier: "SetNotifPageID") as! SetNotificationViewController
    self.present(settingVC, animated: true, completion: nil)

}

但是有没有更好的方法来执行此操作,比如从情节提要中,或者可能使用更正确的方法?

要创建 segue,在故事板中,从一个视图控制器上的 ViewController 图标拖动到第二个视图控制器的视图区域。

然后从 mapView(_:annotationView:calloutAccessoryControlTapped:) 调用 performSegue(identifier:sender)

    func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
        performSegue(withIdentifier: "yourSegueIdFromTheStoryboard", sender: nil)
}

prepare(for:sender:) 配置目标视图控制器。

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let viewController = segue.destination as? SetNotificationViewController {
            // configure your view controller
        }
    }