1

Is it possible in SwiftUI to come back to a specific view? Like when we had controllers The code was this as mention below

let arr = self.navigationController?.viewControllers
for controller in arr!{
            if controller.isKind(of: ViewController.classForCoder()){

     self.navigationController?.popToViewController(controller, animated: true)
            }
} 

Now Let suppose I have 4 Views:-> as mentioned in the code

struct View1: View {
    var body: some View {
        NavigationView {
            NavigationLink(destination: View2()) {
                    Text("Navigate to View2")
                }
        }
    }
}

struct View2: View {
    var body: some View {
        NavigationLink(destination: View3()) {
            Text("Navigate to View3")
        }
    }
}

struct View3: View {
    var body: some View {
        NavigationLink(destination: View4()) {
            Text("Navigate to View4")
        }
    }
}

struct View4: View {
    var body: some View {
        Text("4")
    }
}

Is it possible to pop from View4 to View2??? "Skipping View 3" or From View3 to View 1 Likewise UIKit

Maddy
  • 93
  • 2
  • 9
  • Have you tried to create an Environment Object to decide which screen is gonna be show after appear or disappear? – Renata Faria Oct 14 '19 at 12:45
  • How can you decide from @EnvironmentObject?? – Maddy Oct 14 '19 at 12:52
  • the same problem not getting any solution found out on every social media. As I am using NotificationCenter this is weird crack to this but this works – Maddy Oct 15 '19 at 09:50
  • Take a look at this question https://stackoverflow.com/q/57700532/1291872 I created an open source navigation stack for SwiftUI (https://github.com/biobeats/swiftui-navigation-stack), you can use it to pop to a specific view. – superpuccio Feb 04 '20 at 12:04
  • Thanks @superpuccio for your answer – Maddy Feb 22 '20 at 15:21

0 Answers0