memory - UITabBarController 和解雇
问题描述
在每个 UIViewController 中,我得到了带有简单打印语句的 deinit 函数,该语句告诉我该特定 UIViewController 何时从内存中删除。
deinit {
print("VIEWCONTROLLER DELETED FROM MEMORY")
}
但是,作为 UITabBarController 一部分的所有 UIViewController 永远不会调用 deinit ,我也永远不会在控制台中看到打印语句。
除此之外:
里面的代码...
NotificationCenter.default.addObserver(forName: UIApplication.didChangeStatusBarOrientationNotification, object: nil, queue: OperationQueue.main) { (notification) in
print("Device rotated")
}
...也将在其他选项卡上调用。因此,当设备从横向切换到纵向时,即使我不在特定代码所在的 UIViewcontroller 中,上述闭包内的所有代码也将被执行……奇怪!
这是为什么?
解决方案
好吧,UITabBarController 正在按预期完美运行。可能是你走错了路。如果要观察通知,可以在 UITabBarController 类中观察它,而不是在 UITabBarController 内部的 ViewController 中观察它。有关更多信息,您可以浏览UITabBarController的苹果文档。
推荐阅读
- java - 为什么排除 mybatis-plus 的计数显示 UnsupportedOperationException
- oracle - 远程刷新 Oracle MV
- python - 如何使用 django 禁用 HTML 视图?
- ffmpeg - 使用过滤器复杂的 Ffmpeg 覆盖占用过多的 cpu
- ios - 如何在 Flutter 中保存有状态小部件的数据?
- java - 如何阻止来自外部 jar 的 system.out.println 行
- go - 如何从golang go-redis中的redis.Cmder获取价值?
- ansible - 与剧本一起使用时,Ansible 设置模块的过滤器不起作用
- opencv-python - 将立方体平面切片上的点投影到球坐标
- python - FLASK 表单将数据返回为 Nonetype