我需要从SwiftUI打开UIViewController,UINavigation有后退按钮。
目前,我已经通过ViewControllerRepresentable和NavigationLink实现了这一点,但我有两个Navigations SwiftUI(带后退按钮的NavigationLink(和没有后退按钮的默认UINavigation,我想执行这一操作,使我的默认UINavigation带有后退按钮并隐藏SwiftUI。
struct UIKitVc : UIViewControllerRepresentable {
let navigationController = UINavigationController()
func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {
}
func makeUIViewController(context: Context) -> UINavigationController {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "SearchResult") as! SearchResultViewController
self.navigationController.addChild(viewController)
return self.navigationController
}
}
NavigationLink(destination: UIKitVc(){}
提前谢谢。
如果要使用NavigationView/NavigationLink
,则不需要使用UINavigationController
,只需在UIViewController
上使用representable,如
struct UIKitVc : UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
}
func makeUIViewController(context: Context) -> UIViewController {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier:
"SearchResult") as! SearchResultViewController
// ... make additional set up here if needed
return viewController
}
}