【问题标题】:NSAlert - Added Buttons not appearing in the correct OrderNSAlert - 添加的按钮没有以正确的顺序出现
【发布时间】:2017-10-08 03:55:26
【问题描述】:

我正在尝试创建一个带有 2 个按钮的 NSAlert。

    let a = NSAlert()
    a.messageText = "Do you want go to A or B?"            
    a.alertStyle = .informational
    a.addButton(withTitle: "Yes")
    a.addButton(withTitle: "No")
    a.beginSheetModal(for: self.view.window!, completionHandler: { (modalResponse) -> Void in
    if modalResponse == NSAlertFirstButtonReturn { // do stuff}

问题是按钮No 出现在Yes 之前,第二个按钮似乎已被预选。为什么会这样?

我需要按钮按添加顺序显示,并且没有预选按钮。

【问题讨论】:

  • 按钮放置在警报右侧附近,然后向左侧移动(对于从左到右阅读的语言)。
  • @ColdLogic 好的......谢谢......

标签: swift xcode macos nsalert


【解决方案1】:
  • 通过添加第一个“否”按钮然后添加“是”来修复订单
  • 通过将 keyEquivalent 设置为 "" 来禁用预选

    let alert = NSAlert()
    alert.messageText = "Do you want go to A or B?"
    alert.alertStyle = .informational
    alert.addButton(withTitle: "No")
    alert.addButton(withTitle: "Yes")
    alert.buttons[0].keyEquivalent = ""
    ...
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-04
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 2012-11-22
    • 1970-01-01
    相关资源
    最近更新 更多