Post

Replies

Boosts

Views

Activity

Losing selection of list in NavigationView
I am trying to keep the selection to remain highlighted when navigating back from the destination of the NavigationLink. This code running on iPhone 14 simulator on iOS 16 deselects the current selection or selects 2 items and the count of selected items at the bottom does not match the highlighted items. Am I missing something obvious ? struct ContentView: View { struct Ocean: Identifiable, Hashable { let name: String let id = UUID() } private var oceans = [ Ocean(name: "Pacific"), Ocean(name: "Atlantic"), Ocean(name: "Indian"), Ocean(name: "Southern"), Ocean(name: "Arctic") ] @State private var multiSelection = Set<Ocean>() var body: some View { NavigationView { VStack { List(oceans, id: \.self, selection: $multiSelection) { ocean in NavigationLink { Text(ocean.name) } label: { Text(ocean.name) } } Text("\(multiSelection.count) selected") } .navigationTitle("Oceans") .toolbar { EditButton() } } } }
0
0
311
May ’23