1

I have a NavigationSplitView and an EditButton in the same ContentView. Both do what they should, except that when I click "Edit" and then "Done", the detail view of the last selected item in my list appears. This happens only after I have clicked one of the list items, not before.

var body: some View {
    NavigationSplitView {
        List(selection: $selectedItem) {
            ForEach(items, id: \.self) { item in
                Text(item.timestamp!, formatter: itemFormatter)
            }
            .onDelete(perform: deleteItems)
        }
        .toolbar {
            ToolbarItem(placement: .navigationBarTrailing) {
                EditButton()
            }
            ToolbarItem {
                Button(action: addItem) {
                    Label("Add Item", systemImage: "plus")
                }
            }
        }
        Text("Select an item")
    } detail: {
        NavigationLink(value: selectedItem) {
            Text("Item")
        }
    }
}

The problem doesn't exist with a NavigationStack. Is there any way to get around this?

0 Answers0