当我迅速运行此代码时,我不知道为什么应用程序会在“ alertView.show()”部分显示断点而终止,请有人帮帮我。
var alertView = UIAlertView(
title: "Hey",
message: "Hello",
delegate: self,
cancelButtonTitle: "Cancel"
)
alertView.show()
从Xcode 6.0 UIAlertView类:
不推荐使用UIAlertView。改用UIAlertController和UIAlertControllerStyleAlert的preferredStyle。
在Swift(iOS 8和OS X 10.10)上,您可以执行以下操作:
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”中使用,则只需更改UIAlertControllerStyle,例如:
var alert = UIAlertController(title: "Alert Title", message: "Alert Message", preferredStyle: UIAlertControllerStyle.ActionSheet)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句