我只是想就递归调用 IBAction 函数是否有任何不可预见的问题获得第二意见。我问这个问题是因为曾经发生过一次崩溃,我发现它很难复制。
假设我们有这个电话:
var allowedToSend = false
@IBAction func emailButtonPressed(sender: UIButton) {
if !allowedToSend {
let controller = UIAlertController(title: title,
message: "Are you sure you want to send the Email?",
preferredStyle: .Alert)
controller.addAction(UIAlertAction(title: "Yes please, send.", style: .Default, handler: {
action in
self.allowedToSend = true;
self.emailButtonPressed(sender) // call self again
}))
controller.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: nil))
presentViewController(controller, animated: true, completion: nil)
return // exit the function
}
// Reset the value
allowedToSend = false
// Sending code
let text = textArea.text
let to = toLabel.text
....
}
这是@IBAction
在 Swift 中递归调用的正确方法吗?