【问题标题】:Back button in UIViewControllerRepresentable goes to root view instead of going back to previous viewUIViewControllerRepresentable 中的后退按钮转到根视图而不是返回上一个视图
【发布时间】:2021-05-09 22:31:28
【问题描述】:

我有一个 SwiftUI 应用程序,它具有三个级别:

  • 主列表(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>) {
    
}
}

出现的后退按钮应该返回到次要列表,但它会返回到主列表。

【问题讨论】:

  • 根据您的 3 个级别,我猜您有 2 个导航视图,一个在另一个内部?如果是这样,您应该删除第二个。只要层次结构中的某个位置是 NavigationView,NavigationLink 仍将在辅助屏幕上工作。

标签: swiftui swiftui-navigationlink uiviewcontrollerrepresentable


【解决方案1】:

我解决了我的问题! 我的 UIViewControllerRepresentable 的 NavigationLink 位于 NavigationBar 中,这与层次结构混淆了。

我将 NavigationLink 移到 NavigationBar 之外,现在按预期工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多