ios - 为什么我的 UIAlertController 没有被解雇?

标签 ios swift uialertcontroller

我想在用户打开应用程序时显示一个 UIAlertController

这就是我创建并尝试展示它的方式:

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //simple alert dialog
        let alert=UIAlertController(title: "Alert 1", message: "One is awesome", preferredStyle: UIAlertControllerStyle.Alert);
        //show it
        showViewController(alert, sender: self);

    }
}

为什么不显示?

最佳答案

如果您使用:presentViewController(alert, animated: true, completion: nil)

正如@matt 所说,最好在 ViewDidAppear 中呈现您的 alertViewController 而不是 ViewDidLoad,因为呈现的 viewController 位于界面中。

关于ios - 为什么我的 UIAlertController 没有被解雇?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38815766/

相关文章:

ios - 在应用程序委托(delegate)中全局更改色调后临时更改色调

ios - 想在 UIAlertController 或 UIPopoverController Swift 中显示 UIPickerView?

ios - 在 iOS 中打开包含视频和照片的图库

ios - 在 Cordova 6.4.0 中构建 ios 平台时出错

ios - 永久设置应用程序语言

ios - ld : framework not found DTXProfiler

ios - map 上的折线不可见

swift - 类扩展了 SKScene 但无法访问其属性

ios - 在 Swift 3.0 中将 [String, String] 添加到没有 Optional\"(Help)"的 UIAlertController 消息

ios - 警告 : Presenting view controllers on detached view controllers is discouraged