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 Volley - 如何动画图像加载? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
