在iOS9中UIAlertView这个控件被UIAlertController所取代,虽然UIAlertView暂时还没有被完全废弃,但是这不过是早晚的事情。
let alertController = UIAlertController(title: "通知", message: "确定还是取消", preferredStyle: .alert) // 这里因为控件都不存在改变的可能,所以一律使用let类型.UIAlertControllerStyle可以选择.actionSheet或.alert
let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
let okAction = UIAlertAction(title: "确定", style: .default, handler:{
(UIAlertAction) -> Void in
print("点击确定事件")
})
alertView.addAction(cancelAction)
alertView.addAction(okAction)// 当添加的UIAlertAction超过两个的时候,会自动变成纵向分布
self.present(alertView, animated: true, completion: nil)