如何在 xcode 中加载视图后创建弹出警报
How to create a pop-up alert once the view loads in xcode
我需要在屏幕上加载视图时弹出一个简单的警报。我找到了一些关于如何创建弹出警报的教程,但它们都需要按下 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)
alert that pops up when the view loads on the screen
问题是 "load" 并不 意思是 "on the screen"。你把两个不同的东西混为一谈了。 viewDidLoad
仅仅意味着视图控制器 有 一个视图。直到 viewDidAppear:
,该视图才出现在屏幕上。这就是放置此代码的地方。
我需要在屏幕上加载视图时弹出一个简单的警报。我找到了一些关于如何创建弹出警报的教程,但它们都需要按下 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)
alert that pops up when the view loads on the screen
问题是 "load" 并不 意思是 "on the screen"。你把两个不同的东西混为一谈了。 viewDidLoad
仅仅意味着视图控制器 有 一个视图。直到 viewDidAppear:
,该视图才出现在屏幕上。这就是放置此代码的地方。