【发布时间】:2018-02-20 11:02:27
【问题描述】:
class MyViewController: UIViewController {
// ...
deinit {
print("test deinit")
}
// ...
func exit() {
self.navigationController?.popViewController(animated: true)
}
// ...
}
这是我的视图控制器的(部分),当它出现时总是推入导航控制器。
我希望它在从导航控制器中弹出时取消初始化。
但是当它被任何方法弹出时(调用exit(),刷卡......等),它从未打印过“test deinit”。
我猜呈现方法可能会导致这个问题。所以我测试了以下两种方法。但我无法以任何方式解决它。
let controller = UIStoryboard(name: "MyStoryboard").instantiateViewController(withIdentifier: "MyViewController") as! MyViewController
self.navigationController?.pushViewController(controller, animated: true)
或
self.performSegue(withIdentifier: "ToMyVC", sender: nil)
有什么问题?如何取消初始化?
【问题讨论】:
-
检查你的闭包,委托一定有问题,你的viewController被保留了
-
@ReinierMelian 谢谢。这是正确的。我没有被放在
[unowned self]的众多闭包中。 -
你也可以使用[弱自我]
-
添加为@Byoth的答案
标签: ios swift uiviewcontroller uinavigationcontroller