[英]How to navigate from swift UI to storyboard on button click in swift UI?
I am working on an app that has both swiftUI and storyboard.我正在开发一个同时具有 swiftUI 和 storyboard 的应用程序。 I have a button in swift UI.我在 swift UI 中有一个按钮。 On click of this I need to navigate to a storyboard screen.单击此按钮后,我需要导航到 storyboard 屏幕。 I tried the below code but it is not getting called.我尝试了下面的代码,但没有被调用。 Kindly help....请帮助....
in my swiftUI, the button code is as below,在我的 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) {
}
}
Please help me...请帮我...
Use NavigationLink
with NavigationView
将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)}
)
}
}
}
I found a solution over here,我在这里找到了解决方案,
How to show NavigationLink as a button in SwiftUI 如何在 SwiftUI 中将 NavigationLink 显示为按钮
This works perfectly,这完美地工作,
Button(action: {
print("Floating Button Click")
}, label: {
NavigationLink(destination: AddItemView()) {
Text("Open View")
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.