如何在Swift UIAlertView中显示警报不起作用 [英] How to show an alert in Swift UIAlertView not working

查看:84
本文介绍了如何在Swift UIAlertView中显示警报不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个警报,但是UIAlertView不能快速运行。
我该怎么做?
这是我在Objective-C中执行的操作,但是当我尝试将其转换为快速代码时,它不起作用。

I want to show an alert, but UIAlertView isn't working in swift. How can I do this? This is how I do it in objective-c but when I try to convert it to swift code it doesn't work.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message" 
                                              message:@"Message"
                                             delegate:nil
                                    cancelButtonTitle:@"OK" 
                                    otherButtonTitles:nil];


[alert show];


推荐答案

您应使用 UIAlertController

UIAlertView 已过时。

您可以使用以下代码显示警报:

You can show an alert with this code:

var alert = UIAlertController(title: "Alert", message: "test", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)

这篇关于如何在Swift UIAlertView中显示警报不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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