我有一个SwiftUI NavigationView
,在其中我推到符合UIViewControllerRepresentable
的{{1}}。导航视图自然会添加其后退按钮。但是,我在按键式视图控制器中设置的所有导航栏按钮也都消失了。
添加项目的代码并不是什么新鲜事物,并且如果我从良好的UIKit View Controller中推送,也可以很好地工作:
UIViewController
我的理论是,它们还没有在NavigationView和UIViewController的导航项之间架起桥梁,但也许有人知道解决方法。
答案 0 :(得分:0)
在UIViewControllerRepresentable
中,用UIViewController
包裹UINavigationController
。
struct CustomUIViewControllerRepresentation: UIViewControllerRepresentable {
typealias UIViewControllerType = UINavigationController
func makeUIViewController(context: Context) -> UINavigationController {
let viewController = CustomUIViewController()
let navigationController = UINavigationController(rootViewController: viewController)
return navigationController
}
func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {
}
}