本文介绍了Deinit 从未打过电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 ViewController 对象并将其推送到导航控制器.当对象从堆栈中弹出时 - 它没有被释放并且 Deinit 没有被调用.这可能是什么原因?

I'm creating a ViewController object an pushing it to a navigation controller.When the object is being popped from the stack - it is not being release and Deinit is not being called. What can be the reason for that?

这是推送的代码:

self.navigationController?.pushViewController(CustomViewController(), animated: true)

这是弹出的代码:

 self.navigationController?.popViewControllerAnimated(true)

推荐答案

我遇到了类似的问题.我在我的类中添加了空的 deinit 方法并添加了断点:

I had similar problem. I added empty deinit method to my class and added breakpoint:

deinit {

}

因此它从未被调用过.
一旦我向正文添加了一些代码,它就开始按预期工作:

As result it's never called.
As soon as I add some code to the body it started working as expected:

deinit {
    print("deinit called")
}

因此请确保您的 deinit 方法不为空.
附注.我使用的是 Swift 2,Xcode 7.1

So be sure that your deinit method isn't empty.
PS. I am using Swift 2, Xcode 7.1

这篇关于Deinit 从未打过电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 03:18