我想知道如何在 Swift 中弹出一个对话框游乐场(是的,必须在 Playgrounds 中)我尝试了以下代码(直接来自 AppleDevs 站点)
然而,无论我如何尝试,self
tag always抛出错误。谁能帮我这个?
import UIKit
let alert = UIAlertController(title: "My Alert", message: "This is an alert.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in
NSLog("The \"OK\" alert occured.")
}))
self.present(alert, animated: true, completion: nil)
警报需要从视图控制器呈现。比意味着它将显示在助理编辑器内的模拟器中:
Example:
import UIKit
import PlaygroundSupport
let alert = UIAlertController(title: "My Alert", message: "This is an alert.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in
NSLog("The \"OK\" alert occured.")
}))
let v = UIViewController()
PlaygroundPage.current.liveView = v
v.present(alert, animated: true, completion: nil)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)