我正在尝试使用 iOS 15.0swipeActions并confirmationDialog删除List.
但发生的情况是错误的项目被删除了。
这是我的代码:
struct ConversationsSection: View {
@State private var isShowingDeleteActions = false
let items = ["One", "Two", "Three", "Four", "Five"]
var body: some View {
List(items, id: \.self) { item in
Text(item)
.swipeActions(edge: .trailing) {
Button(role: .destructive) {
isShowingDeleteActions = true
print("Trying to delete: " + item)
} label: {
Label("Delete", systemImage: "trash")
}
}
.confirmationDialog("Delete item?", isPresented: $isShowingDeleteActions) {
Button("Confirm Delete", role: .destructive) {
print("Actually deleting: " + item)
isShowingDeleteActions …Run Code Online (Sandbox Code Playgroud)