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