作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试编写此警报:
func alertUser() {
let alert = NSAlert()
alert.messageText = "message 1"
alert.informativeText = "info1"
alert.informativeText = "info2"
alert.addButton(withTitle: "NO")
alert.addButton(withTitle: "YES")
alert.beginSheetModal(for: self.view.window!) { (returnCode: NSModalResponse) -> Void in
print ("returnCode: ", returnCode)
}
但我在alert.beginSheetModal
unexpectedly found nil while unwrapping an Optional value
消息
请告诉我我做错了什么。
谢谢
最佳答案
您应该从 viewDidAppear
运行您的代码,因为您的 View Controller 尚未在 viewDidLoad
中创建窗口对象。
override func viewDidAppear() {
super.viewDidAppear()
alertUser()
}
关于swift - 我如何在最新的 swift 中编写 NSAlert?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39427088/
我是一名优秀的程序员,十分优秀!