小编Ton*_*ony的帖子

SwiftUI `swipeActions` 和 `confirmationDialog` 删除了错误的项目

我正在尝试使用 iOS 15.0swipeActionsconfirmationDialog删除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)

ios swift swiftui

6
推荐指数
2
解决办法
1880
查看次数

标签 统计

ios ×1

swift ×1

swiftui ×1