gpt4 book ai didi

xcode - NSAlert 多个按钮

转载 作者:搜寻专家 更新时间:2023-10-31 21:52:01 25 4
gpt4 key购买 nike

我有一个带有两个按钮的 NSAlert:

var al = NSAlert()
al.informativeText = "You earned \(finalScore) points"
al.messageText = "Game over"
al.showsHelp = false
al.addButtonWithTitle("New Game")
al.runModal()

它运行完美,但我不知道如何识别用户按下了哪个按钮。

最佳答案

runModal 将返回 "the constant positionally identifying the button clicked."

This是如何定义与您的按钮关联的值:

enum {
NSAlertFirstButtonReturn = 1000,
NSAlertSecondButtonReturn = 1001,
NSAlertThirdButtonReturn = 1002
};

所以,基本上你应该做的是:

NSModalResponse responseTag = al.runModal();
if (responseTag == NSAlertFirstButtonReturn) {
...
} else {
...

关于xcode - NSAlert 多个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27877216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com