首页 > 解决方案 > 在 UIKit 中,当用户滑动删除表格视图单元格时,如何显示确认对话框?

问题描述

是否有相当于 SwiftUI 的 ConfirmDialog (_:isPresented:titleVisibility:actions:)的 UIKit ?

标签: iosswiftuitableviewuikit

解决方案


也许UIAlertController。您必须在 UIViewController 上显示它。例如使用 actionSheet 样式。

let alert = UIAlertController(
    title: "Title",
    message: "Message",
    preferredStyle: .actionSheet
)
alert.addAction(UIAlertAction(
    title: "Delete",
    style: .destructive,
    handler: { _ in
    // delete action
}))
alert.addAction(UIAlertAction(
    title: "Cancel",
    style: .cancel,
    handler: { _ in
    // cancel action
}))
present(alert,
        animated: true,
        completion: nil
)

推荐阅读