[英]How can I navigate to Storyboard VC from SwiftUI View?
I created this SwiftUI View:我创建了这个 SwiftUI 视图:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView{
MasterView()
}.navigationViewStyle(DoubleColumnNavigationViewStyle())
}
}
struct MasterView: View {
var body: some View {
Form {
Section(header: Text("Geplant")) {
Section {
NavigationLink(destination: /* How can I navigate to a Storyboard ViewController?*/) { Text("Berlin") }
}
}
}
.navigationBarTitle("Wähle Reise")
}
}
As you can read, I want to navigate at line "NavigationLink(destination: .....) to a Storyboard VC.如您所见,我想在“NavigationLink(destination: .....) 行导航到 Storyboard VC。
Before, I navigated to the SwiftUI ContentView using a UIHostingController from a UIKit VC.之前,我使用来自 UIKit VC 的 UIHostingController 导航到 SwiftUI ContentView。
Does anyone can help me?有人可以帮助我吗?
Feel free to ask me for other Code/ Screenshots:)随时问我其他代码/屏幕截图:)
Use UIViewControllerRepresentable
使用
UIViewControllerRepresentable
struct UIKitView: UIViewControllerRepresentable {
typealias UIViewControllerType = UIKitViewController
func makeUIViewController(context: Context) -> UIKitViewController {
let sb = UIStoryboard(name: "Main", bundle: nil)
let viewController = sb.instantiateViewController(identifier: "UIKitViewController") as! UIKitViewController
return viewController
}
func updateUIViewController(_ uiViewController: UIKitViewController, context: Context) {
}
}
And then now use然后现在使用
NavigationLink(destination: UIKitView()) { Text("Berlin") }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.