4

This performs as expected, the selection triggers right away

struct ListSelectionTest: View {
  @State var selection: Set<String> = []
  let strings = ["One", "Two", "Three"]
  var body: some View {
    VStack {
      EditButton()
      List(selection: $selection) {
        ForEach(strings, id: \.self) { string in
          Text(string).tag(string)
        }
      }
    }
    .padding()
  }
}

#Preview {
    ListSelectionTest()
}

The problem appears when the List is wrapped in NavigationStack. This does not work:

struct ListSelectionTest: View {
  @State var selection: Set<String> = []
  let strings = ["One", "Two", "Three"]
  var body: some View {
    NavigationStack {
      VStack {
        EditButton()
        List(selection: $selection) {
          ForEach(strings, id: \.self) { string in
            Text(string).tag(string)
          }
        }
      }
      .padding()
    }
  }
}

#Preview {
    ListSelectionTest()
}

When I updated to IOS 17 I found that my EditButton, wrapped in a NavigationStack, won't work the first time you click it. It will work first time if you have already selected a row in the list. But that shouldn't be needed. When I remove the NavigationStack, EditButton works first time as expected, whether there is a selected row in the list or not. On IOS 16.4 EditButton works first time as expected in a NavigationStack, whether there is a selected row in the list or not. I've submitted this to Apple FB13201571. Any thoughts for a workaround?

1 Answer 1

3

This was confirmed by Apple as a SwiftUI bug and was resolved for iOS17.2+.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.