0

I have a list and inside each cell there are multiple navigation links to different views, I thought it was possible but it doesn't work properly, here is an example:

struct ContentView: View {
    var body: some View {
        NavigationView {
            
            List(0..<10) { index in
                HStack {
                    NavigationLink(destination: A()) {
                        Text("\(index) - Destination 1")
                    }
                    
                    NavigationLink(destination: B()) {
                        Text("\(index) - Destination 2")
                    }
                } .padding()
            }
            
        }
    }
}

Is there a workaround or should I rewrite everything using a lazyVStack instead of a list? I'd prefer to use a list since it has built-in swipe and pull to refresh gestures

3
  • 1
    Yes, it is. This stackoverflow.com/a/63497954/12299030 and this stackoverflow.com/a/61188788/12299030 should be helpful. Commented Dec 6, 2021 at 16:00
  • @Asperi thanks but unfortunately it's not suitable for me because with your solution you need to already know the upcoming views and also the data, it works for one layer but if you need to use it more than once it isn't because data may not be available Commented Dec 6, 2021 at 16:56
  • It was not obvious from your question. Then look at this stackoverflow.com/a/62909832/12299030 and entire topic. Commented Dec 6, 2021 at 16:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.