【发布时间】:2015-08-20 09:07:05
【问题描述】:
我用这个简单的代码展示了一个简单的 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
}))
但总会有泄漏。
【问题讨论】:
-
看起来这是一个 iOS 错误。查看this question.
标签: ios swift memory-leaks instruments uialertcontroller