Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在swift UI中单击按钮从swift UI导航到情节提要?_Ios_Swift_Swiftui_Navigation_Storyboard - Fatal编程技术网

Ios 如何在swift UI中单击按钮从swift UI导航到情节提要?

Ios 如何在swift UI中单击按钮从swift UI导航到情节提要?,ios,swift,swiftui,navigation,storyboard,Ios,Swift,Swiftui,Navigation,Storyboard,我正在开发一款既有swiftUI又有故事板的应用程序。我在swift UI中有一个按钮。点击这个我需要导航到一个故事板屏幕。我尝试了下面的代码,但没有被调用。请帮忙 在我的swiftUI中,按钮代码如下所示 Button(action:{ TestController() }, label:

我正在开发一款既有swiftUI又有故事板的应用程序。我在swift UI中有一个按钮。点击这个我需要导航到一个故事板屏幕。我尝试了下面的代码,但没有被调用。请帮忙

在我的swiftUI中,按钮代码如下所示

    Button(action:{ TestController()
                                    
                                }, label:
                                    {
                                        Text("Click me").foregroundColor(.white)
                                        Image(systemName: "chevron.forward.2").imageScale(.large)})



struct TestController: UIViewControllerRepresentable {
    
    func makeUIViewController(context: Context) -> some UIViewController {
        let storyboard = UIStoryboard(name: "test", bundle: Bundle.main)
        let controller = storyboard.instantiateViewController(identifier: "testView")
        return controller
    }
    
    func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
       
    }
}

请帮助我…

使用
NavigationLink
NavigationView

struct MyTestView: View {
    var body: some View {
        NavigationView {
            NavigationLink(
                destination: TestController(),
                label: {
                    Text("Click me").foregroundColor(.white)
                    Image(systemName: "chevron.forward.2").imageScale(.large)}
            )
        }
    }
}

我在这里找到了解决办法

这很好用

Button(action: {
    print("Floating Button Click")
}, label: {
    NavigationLink(destination: AddItemView()) {
         Text("Open View")
     }
})

“我尝试了下面的代码,但没有被调用”首先,下面的单词不是形容词。其次,什么是不被调用的?我相信你应该使用
InstanceViewController(带标识符:)
,但我不确定这是否是问题所在。为什么不使用直接导航线路????不需要按钮。可能有不同的方法。但我的要求是。。。。因为它是现有代码,并且由于旧功能而无法更改UI元素