如何从 SwiftUI 视图导航到 Storyboard VC? [英] How can I navigate to Storyboard VC from SwiftUI View?
本文介绍了如何从 SwiftUI 视图导航到 Storyboard VC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了这个 SwiftUI 视图:
I created this SwiftUI View:
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")
}
}
如您所见,我想在NavigationLink(destination: .....)"行导航到 Storyboard VC.
As you can read, I want to navigate at line "NavigationLink(destination: .....) to a Storyboard VC.
之前,我使用 UIKit VC 中的 UIHostingController 导航到 SwiftUI ContentView.
Before, I navigated to the SwiftUI ContentView using a UIHostingController from a UIKit VC.
有人可以帮助我吗?
请随时向我索取其他代码/屏幕截图 :)
Feel free to ask me for other Code/ Screenshots :)
推荐答案
Use 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) {
}
}
然后现在使用
NavigationLink(destination: UIKitView()) { Text("Berlin") }
这篇关于如何从 SwiftUI 视图导航到 Storyboard VC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文