UITabViewController 内存管理
我有一个应用程序,其中包含由从 UITabBarController 派生的类管理的多个选项卡(我子类化 UITabBarConteroller 的唯一原因是处理所有视图的摇动事件)。 3 个视图来自 UIViewContentroller 类的子类,一个视图是 UINavigationController,它显示一个表格。 在我拥有的每一个控制器中,包括我的子类控制器,我都有这个:
- (void)didReceiveMemoryWarning { // 如果视图没有父视图,则释放该视图。 [超级didReceiveMemoryWarning];
应用程序运行良好。我的问题是 UITabBarController 的默认实现如何在内存不足的情况下处理自动视图卸载。
只有从 UINavigationController 派生的控制器会自动卸载(我看到 viewDidUnload 被调用)。 viewDidUnload 不会被 UITabBarController 管理的任何其他视图控制器调用。
为什么?
谢谢
I have an app which consists multiple tabs managed by the class derived from UITabBarController (the only reason I subclassed UITabBarConteroller is to handle shake event for all views). 3 views are from subclassed UIViewContentroller class, one view is UINavigationController which shows a table.
In every single controller I have, including my subclassed one, I have this:
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
App works great. My question is how is default implementation of UITabBarController handles automatic view unloading on low memory conditions.
Only controller derrived from UINavigationController unload automatically (I see viewDidUnload called). viewDidUnload is NOT called for any other view controllers managed by UITabBarController.
Why?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当视图控制器的视图被删除和释放时,viewDidUnload 会被调用,这会在 VC 收到 didReceiveMemoryWarning 之后发生。首先检查该方法是否被调用。如果它没有被调用,则说明正在发生其他事情,但如果它被调用,那么您的视图可能被过度保留或没有被正确删除。
viewDidUnload gets called when your view controller's view is removed and deallocated, and this happens after the VC receives didReceiveMemoryWarning. Check for that method being called first. If it's not being called, something else is going on, but if it is being called, then perhaps your view is over retained or not being removed properly.