2017-10-08 95 views
0

我试图用2个按钮创建一个NSAlert。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} 

问题是按钮NoYes之前Appers和第二个按钮似乎preselected.Why会出现这种情况?

我需要这些按钮按照它们的添加顺序出现,并且没有预先选择按钮。通过将第一个 “否” 按钮

+0

按钮被放置出发靠近警报的右侧并朝向左侧(用于从左至右读取的语言)。 – ColdLogic

+0

@ColdLogic好吧....谢谢......... – techno

回答

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 = "" 
    ... 
    

enter image description here

+0

谢谢.......... – techno

相关问题