首页 > 解决方案 > 使用 SwiftUI 按钮导航到 Storyboard

问题描述

这是我的 SwiftUI 代码:

//

    .navigationBarItems(trailing:
     HStack {
         Button(action: {
            AddView() // NOT WORKING
         }) {
             Image(systemName: "plus.square.fill")
                 .font(.largeTitle)
         }.foregroundColor(.blue)
     })

如您所见,我想调用 AddView(),以使用导航栏中的按钮导航到添加视图。这是我的 AddView() 函数:

struct AddView: UIViewControllerRepresentable {
typealias UIViewControllerType = SwipeViewController

func makeUIViewController(context: Context) -> SwipeViewController {
    let sb = UIStoryboard(name: "Storyboard", bundle: nil)
    let viewController = sb.instantiateViewController(identifier: "add") as! SwipeViewController
    return viewController
}

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

}

它确实导航到我称为“添加”的 Storyboard VC...

怎么了?谢谢你!

标签: iosswiftswiftui

解决方案


推荐阅读