SwiftUI navigation from collapse list

Viewed 129

I have collapse list in main view, i wanna to go in another view when i tap in a child of section in list, i tried but it didint work. Nothing didnt change when i tapped. What im doing wrong ?

 func sectionIndex(section : Theme) -> Int {
    userData.data.firstIndex(where: {$0.name == section.name})!
 }
 var body: some View {
        
        NavigationView {
            List {
                ForEach(userData.data) { section in
                    Section(header: HeaderView(section: section)
                                .onTapGesture {
                                    self.userData.data[self.sectionIndex(section: section)].expanded.toggle()
                                }, footer: EmptyView()) {
                        
                        if section.expanded {
                            
                            ForEach(section.questions!) { question in
                                QuoteView(question: question)
                                    .onTapGesture {
                                        
                                        NavigationLink(destination: DetailView()) {
                                            Text("Do Something")
                                        }
                                        print("dsdsw")
                                    }
                            }
                        }
                    }
                }
            }
        }
        
        
    }
    
    
}


struct DetailView : View {
    var body: some View {
        Text("Hello World B")
    }
}
1 Answers

I don't know what is QuoteView, but try to put link into background of that view, NavigationView should handle link in it automatically, ie.

ForEach(section.questions!) { question in
    QuoteView(question: question)
        .background (
            NavigationLink(destination: DetailView()) {
                EmptyView() // << content is not needed here
            }
        )
}
Related