我想弄清楚如何创建一个弹出窗口,只有在你启动应用程序时才出现一次,然后除非你关闭应用程序并重新启动它,否则不会再出现.但是,如果您查看下面的代码,您将意识到每次ViewController出现时都会弹出警报.例如,如果您转到设置选项卡然后返回主ViewController菜单,则会弹出警报.
override func viewDidAppear(animated: Bool) {
let alertController = UIAlertController(title: "Disclaimer", message: "WARNING: Please ride carefully!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Accept", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud) 我需要一个简单的警报,当视图加载到屏幕上时会弹出.我已经找到了一些关于如何创建弹出警报的教程,但它们都需要按下UI按钮.我需要它只是在视图加载时自动弹出.
这是我的代码的开始,但是我无法弄清楚如何调用代码而不必使用UIbutton操作:
override func viewDidLoad() {
super.viewDidLoad()
let alertController = UIAlertController(title: "Disclaimer", message:
"Hello, world!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Accept", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)