我使用这个简单的代码呈现一个简单的 UIViewController
@IBAction func addNewFeed(sender: UIBarButtonItem)
{
var alertView: UIAlertController? = UIAlertController(title: NSLocalizedString("New Feed", comment: "Titolo popup creazione feed"),
message: NSLocalizedString("Insert the Title and the Link for the new Feed.", comment: "Messaggio creazione nuovo feed"),
preferredStyle: UIAlertControllerStyle.Alert)
alertView!.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "Annulla popup creazione nuovo feed"),
style: UIAlertActionStyle.Cancel,
handler: nil))
presentViewController(alertView!, animated: true, completion: nil)
}
当我按下界面上的按钮时,我调用此 IBAction 并出现 UIAlertController。但是,当我单击“取消”按钮关闭控制器时,泄漏工具发现了泄漏,如下图所示:
我尝试在处理程序参数中放置这样的闭包:
alertView!.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "Annulla popup creazione nuovo feed"),
style: UIAlertActionStyle.Cancel,
handler: {[weak self] action in self!.dismissViewControllerAnimated(true, completion: nil)
alertView = nil
}))
但总是有这种泄漏。