我想显示一个警报,我做到了。但是有一个问题:我无法更改全局值或在 的处理程序中添加UIAlertAction
函数UIAlertController
。例如:
let alertController = UIAlertController(title: "",
message: "Do you want to leave ?", preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default,
handler: {
action in
self.appDelegate.globalvalue = true
})
alertController.addAction(cancelAction)
alertController.addAction(okAction)
if let popoverController = alertController.popoverPresentationController {
popoverController.sourceView = sender as! UIView
popoverController.sourceRect = sender.bounds
}
self.presentViewController(alertController, animated: true, completion: nil)
我添加了ofself.appDelegate.globalvalue = true
的处理程序,但值始终为 false...未更改为 true...UIAlertAction
UIAlertController
self.appDelegate.globalvalue
self.appDelegate.globalvalue
如何更改 of 的处理程序中的UIAlertAction
值UIAlertController
?或者我可以在警报上单击“确定”后更改全局值吗?谢谢你的一切:)