Deinit never called(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 方法不为空.
PS.我正在使用 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 从未调用过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Deinit 从未调用过
基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
