如何解决UIViewControllerRepresentable 中的后退按钮转到根视图而不是返回上一个视图
- 主列表(SwiftUI NavigationView)
- 二级列表(SwiftUI NavigationView)
- 一个 UIViewControllerRepresentable
在我的二级列表中
NavigationLink(destination: ARView(museum: self.museum)) {
Image(systemName: "camera.viewfinder")
})
然后在 UIViewControllerRepresentable 我有
struct ARView: UIViewControllerRepresentable {
var museum:Museum?
var work:Work?
func makeUIViewController(context: UIViewControllerRepresentableContext<ARView>) -> UIViewController {
let ARVC = ARViewController(nibName: "ARViewController",bundle: .main)
if let museum = museum {
ARVC.visitedMuseum = museum
ARVC.ARExperience = false
LoggingSystem.push(eventLog: ["event":"AR opened","museum":ARVC.visitedMuseum.name],verbose: false)
}
if let work = work {
ARVC.visitedWork = work
ARVC.VRonly = true
LoggingSystem.push(eventLog: ["event":"Work selected","work":ARVC.visitedWork.name],verbose: false)
}
return ARVC
}
func updateUIViewController(_ uiViewController: UIViewController,context: UIViewControllerRepresentableContext<ARView>) {
}
}
出现的后退按钮应该返回到二级列表,但它返回到主列表。
解决方法
我解决了我的问题! 到我的 UIViewControllerRepresentable 的 NavigationLink 位于 NavigationBar 中,这与层次结构混乱。
我将 NavigationLink 移到了 NavigationBar 之外,现在按预期工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。