A possible solution is to force redraw the List
:
struct ContentView: View {
@State private var names = ["david", "john", "amber"]
@State private var listId = UUID()
var body: some View {
List {
ForEach(names, id: .self) { item in
Text(item)
}
.onDelete(perform: deleteItem)
}
.id(listId)
}
private func deleteItem(at indexSet: IndexSet) {
names.remove(atOffsets: indexSet)
listId = UUID()
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…