我需要打开UIViewController从SwiftUI与UINavigation有后退按钮。
目前,我已经通过ViewControllerRepresentable和NavigationLink实现了这一点,它的工作,但我有两个导航SwiftUI(NavigationLink与后退按钮)和默认的UINavigation没有后退按钮,我想执行我的默认UINavigation与后退按钮和隐藏SwiftUI(NavigationLink)导航。
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(){}提前谢谢你。
发布于 2020-10-09 22:16:16
如果你打算使用NavigationView/NavigationLink,那么你不需要使用UINavigationController,只需在你的UIViewController上使用可表示,比如
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
}
}https://stackoverflow.com/questions/64279975
复制相似问题