1

我需要使用带有后退按钮的 UINavigation 从 SwiftUI 打开 UIViewController。

目前,我已经通过 ViewControllerRepresentable 和 NavigationLink 实现了这个,它的工作原理,但是我有两个导航 SwiftUI(带有后退按钮的 NavigationLink)和没有后退按钮的默认 UINavigation,我想执行让我的默认 UINavigation 带有后退按钮并隐藏SwiftUI(NavigationLink) 导航。

struct UIKitVc : UIViewControllerRepresentable {


   let navigationController =  UINavigationController()

   func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {
   }


   func makeUIViewController(context: Context) -> UINavigationController {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let viewController = storyboard.instantiateViewController(withIdentifier: "SearchResult") as! SearchResultViewController
      self.navigationController.addChild(viewController)

        return self.navigationController
   }
}


NavigationLink(destination: UIKitVc(){}

先感谢您。

4

1 回答 1

0

如果你要使用,NavigationView/NavigationLink那么你不需要使用UINavigationController,只需在你的上使用可表示的UIViewController,比如

struct UIKitVc : UIViewControllerRepresentable {


   func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
   }

   func makeUIViewController(context: Context) -> UIViewController {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let viewController = storyboard.instantiateViewController(withIdentifier: 
            "SearchResult") as! SearchResultViewController

        // ... make additional set up here if needed

        return viewController
   }
}
于 2020-10-09T14:16:15.833 回答