如何使用 MacOS 應用程式從選單項中顯示警報對話框SwiftUI?適用于iOS但不起作用的常用@State var isOn = false代碼.alert("title", isPresented: isOn) {..}。
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}.commands {
CommandMenu("Test menu") {
Button(action: {
// I want to show an alert dialog dialog here.
}) {
Text("Click Me")
}
}
}
}
uj5u.com熱心網友回復:
通常的代碼作業正常。你永遠不會嘗試Alert在Button. 你不會在這里做的。
@main
struct MyApp: App {
@State var isOn = false
var body: some Scene {
WindowGroup {
NavigationView {
ContentView()
.alert("title", isPresented: $isOn) {
Button("OK", role: .cancel) { }
}
}
}.commands {
CommandMenu("Test menu") {
Button(action: {
isOn = true
}) {
Text("Click Me")
}
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/436416.html
