0

I have a SwiftUI app that has three levels:

  • Main List (SwiftUI NavigationView)
  • Secondary List (SwiftUI NavigationView)
  • An UIViewControllerRepresentable

In my secondary list I have

NavigationLink(destination: ARView(museum: self.museum)) {
    Image(systemName: "camera.viewfinder")
})

And then in the UIViewControllerRepresentable I have

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>) {
    
}
}

The back button that appears should go back to the Secondary List, but instead it goes back to the Main List.

  • Based on your 3 levels, I'm guessing you have 2 navigation views and one is inside the other? If so, you should remove the 2nd one. The NavigationLink will still work from a secondary screen as long as somewhere in the hierarchy is a NavigationView. – nicksarno Feb 05 '21 at 19:17

1 Answers1

0

I solved my problem! The NavigationLink to my UIViewControllerRepresentable was in the NavigationBar and that messed up with the hierarchy.

I moved the NavigationLink outside of the NavigationBar and now is working as expected.