是否可以使用处理程序触发其他警报?如何使用UIAlertAction的“处理程序”调用另一个UIAlertAction?
func jokeFinal() {
let alert = UIAlertController(title: "Never Mind", message: "It's Pointless", preferredStyle: .alert)
let action = UIAlertAction(title: "Hahahahahaha", style: .default, handler: nil)
alert.addAction(action)
present(alert, animated: true, completion: nil)
}
func joke() {
let alert = UIAlertController(title: "A broken pencil", message: "...", preferredStyle: .alert)
let action = UIAlertAction(title: "A broken pencil who?", style: .default, handler: jokeFinal())
alert.addAction(action)
present(alert, animated: true, completion: nil)
}
@IBAction func nock() {
let alert = UIAlertController(title: "Knock,Knock", message: "..", preferredStyle: .alert)
let action = UIAlertAction(title: "Who's there??", style: .default, handler: joke())
alert.addAction(action)
present(alert, animated: true, completion: nil)
}
我试图用一个UIAlertAction
的处理程序调用另一个UIAlert
。可能吗?
我收到以下错误:
Cannot convert value of type '()' to expected argument type '((UIAlertAction) -> Void)?'