UIAlertView在Swift中不起作用 [英] UIAlertView is Not Working in Swift
问题描述
当我在swift中使用此代码时,我不知道为什么应用程序通过在alertView.show()部分中显示断点来终止,有人请帮助我。
when i runt this code in swift, i dont know why the app terminates by showing a break point in the "alertView.show()" part, Somebody please help me.
var alertView = UIAlertView(
title: "Hey",
message: "Hello",
delegate: self,
cancelButtonTitle: "Cancel"
)
alertView.show()
推荐答案
来自Xcode 6.0 UIAlertView类:
From Xcode 6.0 UIAlertView class:
不推荐使用UIAlertView。改为使用UIAlertController和UIAlertControllerStyleAlert的preferredStyle
。
UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead.
在swift(iOS 8和OS X 10.10)上,你可以做这个:
On swift ( iOS 8 and OS X 10.10 ), you can do this:
var alert = UIAlertController(title: "Alert Title", message: "Alert Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Cancel, handler:handleCancel))
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler:{ (ACTION :UIAlertAction!)in
println("User click Ok button")
}))
self.presentViewController(alert, animated: true, completion: nil)
func handleCancel(alertView: UIAlertAction!)
{
println("User click cancel button")
}
如果你想在'ActionSheet'中使用'Alert',你只需要更改UIAlertCon例如:trollerStyle:
If you want to use in 'ActionSheet' instead 'Alert' you need only to change the UIAlertControllerStyle for example:
var alert = UIAlertController(title: "Alert Title", message: "Alert Message", preferredStyle: UIAlertControllerStyle.ActionSheet)
这篇关于UIAlertView在Swift中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!