如何在打开在线网页的 NSAlert 中放置问号按钮?

Cue*_*Cue 5 macos nsalert

编辑:我的问题不是很清楚,现在我对其进行了编辑,以明确我需要打开在线网页而不是帮助手册。

\n\n

我想在 macOS 项目的 NSAlert 中包含一个问号按钮,该按钮指向带有帮助资源的在线网页。

\n\n

在这里看到有两种可能性:

\n\n
\n

var showHelp: Bool 指定警报是否有帮助按钮。

\n\n

var helpAnchor:字符串?Alert\xe2\x80\x99s HTML 帮助锚点。

\n
\n\n

但我不知道如何实现它。

\n\n

我使用这段代码:

\n\n
@IBAction func buttonPressed(_ sender: Any) {\n    let myAlert: NSAlert = NSAlert()\n\n    myAlert.messageText = "Message"\n    myAlert.informativeText = "Informative text."\n\n    myAlert.showsSuppressionButton = true\n\n    myAlert.addButton(withTitle: "Later")\n    myAlert.addButton(withTitle: "Now")\n    myAlert.addButton(withTitle: "OK")\n\n    let choice = myAlert.runModal()\n\n    switch choice {\n    case NSAlertFirstButtonReturn:\n        print ("OK")\n    case NSAlertSecondButtonReturn:\n        print ("Now")\n    case NSAlertThirdButtonReturn:\n        print ("Later")\n    default: break\n\n    }\n    if myAlert.suppressionButton!.state == 1 {\n        print ("Checked")\n    } else {\n        print ("Not checked")\n    }\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n

Ken*_*ses 3

您应该使您的控制器类符合NSAlertDelegate.
然后,设置myAlert.delegate = selfmyAlert.showsHelp = true
在您的控制器类中,实现func alertShowHelp(_ alert: NSAlert) -> Bool您喜欢的任何操作。

一般来说,要在用户的默认浏览器中打开 URL,请使用NSWorkspace及其open()方法。