Hi there! I'm trying to separate my NavigationLinks because when I click a navigationLink, the entire VStack gets clicked but I only wan't one NavigationLink. Could someone help me fix this?
Code Block swift var body: some View { VStack { GeometryReader { geometry in VStack { List { VStack(alignment: .leading) { Text("Open:").font(.headline).padding() Divider() ForEach(self.viewModel.eventsList) { event in if event.completed == false { NavigationLink(destination: EventInProgressView(event: event) .environmentObject(viewModel)) { EventsListItemView(event: event) .foregroundColor(Color.black) .environmentObject(viewModel) } } }.onDelete(perform: delete) } //there's some more stuff down here
You should better include all the code to reproduce your issue. Nearby view or enclosing view may affect the behavior.//there's some more stuff down here
With putting a VStack directly under the List, you are telling SwiftUI to treat the VStack as a single item.
Can't you use Section?
Code Block var body: some View { VStack { GeometryReader { geometry in VStack { List { Section(header: VStack(alignment: .leading) { Text("Open:").font(.headline).padding() Divider() } ) { ForEach(self.viewModel.eventsList.filter{!$0.completed}) { event in NavigationLink(destination: EventInProgressView(event: event) .environmentObject(viewModel)) { EventsListItemView(event: event) .foregroundColor(Color.black) .environmentObject(viewModel) } }.onDelete(perform: delete) } //there's some more stuff down here } } } } }