[英]uiViewController Swift IOS
I am using swift and have a class called ViewController() that is linked to my storyboard. 我正在使用swift,并具有一个称为ViewController()的类,该类链接到我的情节提要。 I am trying to get an alert view to display from another class.
我正在尝试从另一个班级显示一个警报视图。 I am using the following code however it will not open an alert box.
我正在使用以下代码,但不会打开警报框。 Any Ideas?
有任何想法吗?
public class SomeClass {
func showAlert(title:String, body:String) {
var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
}
You have to call presentViewController
on your UIViewController
and pass in your UIAlertViewController
. 您必须在
UIViewController
上调用presentViewController
并传递UIAlertViewController
。
In UIViewController: 在UIViewController中:
self.presentViewController(alert, animated: true, completion: nil)
self.presentViewController(警告,动画:true,完成:无)
alert
being your UIAlertViewController
. alert
是您的UIAlertViewController
。
func showAlert(title:String, body:String) {
var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
var vc: ViewController = ViewController()
vc.presentViewController(alert, animated: true, completion: nil)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.