首页 > 解决方案 > 当我们在 View Xcode 13 中使用确认对话框时,没有显示警报

问题描述

struct ConfirmationDialog: View {
    @State private var showingOptions = false
    @State private var showingAlert = false

    var body: some View {
        VStack {
            Button("Show Options") {
                showingOptions = true
            }
            .alert("Alert Title", isPresented: $showingAlert, actions: {
                Button {
                    // Do nothing
                } label: {
                    Text("Okay")
                }
            }, message: {
                Text("Alert Message")
            })
            .confirmationDialog("Select option", isPresented: $showingOptions, titleVisibility: .visible) {
                Button("Show Alert") {
                    self.showingAlert = true
                }
            }
        }
    }
}

当我在单个视图中使用确认对话框和警报时,警报不会出现。

当第一次出现确认对话框时,我得到一个控制台日志。

在已显示确认对话框时尝试显示警报。这是不支持的。

我正在使用 XCode 13 和 iOS 15 模拟器

它是 XCode 13 中的错误吗?

标签: swiftuiios15xcode13

解决方案


推荐阅读