相关疑难解决方法(0)

从 SwiftUI 视图转到 UIViewController

我正在努力将一些 SwiftUI 内容实施到我现有的应用程序中。我目前有一个 UIViewController,它承载一个用于相机预览的 MTKView。

我创建了一个新的 SwiftUI 视图,它现在是我的视图,如我的SceneDelegate.swift文件中所设置。SwiftUI 视图按预期在启动时加载。现在,我想创建一个 segue,当用户点击我列表中的一行时,它将全屏显示到我现有的 UIViewController。这是我如何称呼它的;

var body: some View {
    VStack {
        NavigationView {
            List(sessionTypes) { session in
                NavigationLink(destination: CameraControllerWrapper()) {
                    SessionRow(session: session)
                    .frame(height: 40.0)
                }
            }
        .navigationBarTitle(Text("Camera Types"))
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

对于后代,这是我的CameraControllerWrapperUIViewControllerRepresentable;

struct CameraControllerWrapper: UIViewControllerRepresentable {
typealias UIViewControllerType = CameraController

   func makeUIViewController(context: UIViewControllerRepresentableContext<CameraControllerWrapper>) -> CameraControllerWrapper.UIViewControllerType {
    return CameraController()
   }

   func updateUIViewController(_ uiViewController: CameraControllerWrapper.UIViewControllerType, context: UIViewControllerRepresentableContext<CameraControllerWrapper>) {
    //
   }
}
Run Code Online (Sandbox Code Playgroud)

虽然这“有效”,但一旦调用 CameraController,我的应用程序就会崩溃,因为似乎找不到我的任何 IBOutlets。CameraController 是一个内置在故事板中的 UIViewController。

ios swiftui

11
推荐指数
1
解决办法
2803
查看次数

标签 统计

ios ×1

swiftui ×1