我正在尝试构建UIViewController包装器以在SwiftUI中显示UIViewControllers。现在我正在
无法在此文件中预览-发生意外错误
哪种SwiftUI在误导性和模糊性错误方面已经很经典。无论如何,这是我包装器类的代码。很难找到它,因为大多数在线示例都是ViewController,而不是UIViewController。
struct WrapperUIView: UIViewControllerRepresentable{
typealias UIViewControllerType = UIViewController
let storyboard: String
let VC: String
func makeUIViewController(context: UIViewControllerRepresentableContext<WrapperUIView>) -> WrapperUIView.UIViewControllerType {
//load the storyboard
let loadedStoryboard = UIStoryboard(name: storyboard, bundle: nil)
//load the viewcontroller
return loadedStoryboard.instantiateViewController(withIdentifier: VC)
}
func updateUIViewController(_ uiViewController: WrapperUIView.UIViewControllerType, context: UIViewControllerRepresentableContext<WrapperUIView>) {
}
}
struct HomeUIView_Previews: PreviewProvider {
static var previews: some View{
HomeUIView(storyboard: "Main", VC: "HomeViewController")
}
}
所以这里有些问题,但是我不知道是什么..这是调用上述视图的代码。
struct TabMotherView: View{
@ObservedObject var viewRouter = TabViewRouter()
//@State var page = "Search"
var body: some View{
return VStack{
if self.viewRouter.currentView == "Search"{
//HseNearMissView()
WrapperUIView(storyboard: "Main", VC: "HomeViewController")
} else if self.viewRouter.currentView == "Documents" {
CustomSwiftUIView()
}
}
}
}
如果我删除了WrapperUIView(),则“ CustomSwiftUIView()”显示的很好。这意味着我的错误肯定被缩小到WrapperUIView()
有什么想法吗?