Segue To UIViewController From SwiftUI View

后端 未结 1 1808
北恋
北恋 2020-12-20 15:12

I am working to implement some SwiftUI content into my existing app. I currently have a UIViewController, which hosts a MTKView for camera preview.

I have created a

相关标签:
1条回答
  • 2020-12-20 15:59

    I managed to resolve this by realizing that I needed to instantiate the UIViewController from the Storyboard, and not in code (as I had built its layout in Storyboard, alongside some programatic elements). To use the above NavigationLink, I needed to adjust my UIViewControllerRepresentable as such;

    struct CameraControllerWrapper: UIViewControllerRepresentable {
        typealias UIViewControllerType = CameraController
    
        func makeUIViewController(context: UIViewControllerRepresentableContext<CameraControllerWrapper>) -> CameraControllerWrapper.UIViewControllerType {
    
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let mainViewController: CameraController = mainStoryboard.instantiateViewController(withIdentifier: "CameraController") as! CameraController
          return mainViewController
    
        }
    
        func updateUIViewController(_ uiViewController: CameraControllerWrapper.UIViewControllerType, context: UIViewControllerRepresentableContext<CameraControllerWrapper>) {
            //
        }
    }
    
    0 讨论(0)
提交回复
热议问题