如何使用UIAlertController呈现警报 [英] How to present an alert with UIAlertController

查看:90
本文介绍了如何使用UIAlertController呈现警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用swift发出警报。
这是我在viewDidLoad中使用的代码,但是在运行代码时没有任何反应。
有人可以帮忙吗?

I am trying to present an alert using swift. This is the code I used from viewDidLoad but nothing happens when the code is run. Can someone help?

    var alert = UIAlertController(title: "test title",
        message: "test message",
        preferredStyle: .Alert)
    self.presentViewController(alert, animated: true, completion:nil)


推荐答案

在出现任何父视图之后,您必须显示任何视图控制器。将您的演示文稿代码放入viewDidApear方法。

You must present any view controller after its parent view has been appeared . Put your presentation code to viewDidApear method.

override func viewDidAppear(animated: Bool)
    {
        super.viewDidAppear(animated)

        var alert = UIAlertController(title: "test title",
            message: "test message",
            preferredStyle: .alert)
        self.present(alert, animated: true, completion:nil)

    }

这篇关于如何使用UIAlertController呈现警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆