Skip to content

Instantly share code, notes, and snippets.

@phillipcaudell
Last active May 8, 2023 11:10
Show Gist options
  • Save phillipcaudell/3b890345efbc36c050d3ec630051c200 to your computer and use it in GitHub Desktop.
Save phillipcaudell/3b890345efbc36c050d3ec630051c200 to your computer and use it in GitHub Desktop.
If you add a selection binding to a List (let's say you want to edit it), then that seemingly renders all NavigationLinks in the List unusable. Surely not!?
import SwiftUI
struct BrokenNavigationLinksView: View {
@State private var selection = Set<Int>()
var body: some View {
NavigationStack {
// List {
List(selection: $selection) {
ForEach(0...50, id: \.self) { id in
// Won't do anything, unless the selection binding has been removed from the List
NavigationLink(value: id) {
Text("Row \(id)")
}
}
}
.navigationDestination(for: Int.self) { row in
DetailView(row: row)
}
.toolbar {
EditButton()
}
}
}
}
struct DetailView: View {
let row: Int
var body: some View {
Text("Detail View \(row)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment