[英]UIViewController isn't deinitialized
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
正在被保留
确保您的代表被声明为weak
,
weak var delegate: YourDelegateProtocol
并且您使用self
的闭包使用[weak self]
或[unowned self]
let yourClosure : (()->Void) = { [weak self] in
//your closure implementation
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.