且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将Storyboard ViewController添加到SwiftUI项目中?

更新时间:2023-02-16 23:19:31

您刚刚通过类初始化程序创建了控制器,要从情节提要中实例化它,您必须像下面这样

You just created controller by class initialiser, to instantiate it from storyboard you have to do like the following

func makeUIViewController(context: 
         UIViewControllerRepresentableContext<AssetsListView>) -> AssetsListViewController {
    let storyboard = UIStoryboard(name: "Main",     // < your storyboard name here
          bundle: nil)
    let assetsListVC = storyboard.instantiateViewController(identifier: 
          "AssetsListViewController")      // < your controller storyboard id here

    assetsListVC.taskID = taskID
    return assetsListVC

}