let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
alert.addAction(UIAlertAction(title: "lala", style: UIAlertActionStyle.Cancel, handler: { (action) in
switch action.style{
case .Default:
print("default")
case .Cancel:
print("cancel")
case .Destructive:
print("destructive")
}
}))
alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { action in
switch action.style{
case .Default:
print("default")
case .Cancel:
print("cancel")
case .Destructive:
print("destructive")
}
}))
本文展示如何在Swift中使用UIAlertController创建弹窗警报,包括设置标题、消息、样式及添加不同类型的按钮,并演示了按钮点击后的处理逻辑。

被折叠的 条评论
为什么被折叠?



