视图将消失未触发
我正在使用 addSubView 方法来添加视图。 viewWillDisappear 有其他替代方法吗? viewWillDisappear 没有触发。我想在当前视图消失时释放所有分配的对象。目前我正在使用 dealloc 方法来执行此操作。但 dealloc 方法的触发速度并不快。由于我收到内存警告,有时我的应用程序可能会自行崩溃。主要问题是语音文件。
i am using addSubView method to add views. Did any alternative methods are there for viewWillDisappear? viewWillDisappear is not firing. I want to release all allocated objects when the current view get dissapear. Currently i am using dealloc method to do this. But dealloc method is firing not quickly. Since i am getting memory warings and sometimes the my app may crash itself. The main problem is with voice files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
addSubview/removeFromSuperview(这些方法与视图相关,而不是视图控制器)不会调用 viewWillAppear/viewWillDisappear 方法。您应该在 dealloc() 本身中编写释放对象代码。
removeFromSuperview 应该调用 dealloc()。
addSubview/removeFromSuperview (these methods relate with views not view controllers) doesnt call viewWillAppear/viewWillDisappear methods. You should write release object code in dealloc() itself.
removeFromSuperview should call dealloc().
您可以尝试在方法
viewDidDisappear
中release
对象。那么你就不会等待触发方法dealloc
。另外,在方法
viewDidDisappear
中,您可以尝试从超级视图中删除所有子视图(这将对所有子视图调用viewWillDisappear
):You can try to
release
objects in methodviewDidDisappear
. Then you won't wait for firing methoddealloc
.Also in method
viewDidDisappear
you can try to remove all subviews from superview (that will callviewWillDisappear
to all subviews):在 viewDidUnload/viewDidDisappear 中释放对象并在 dealloc 中设置为 nil
这可能会起作用,但你一定应该看看为什么 viewWillDisappear 没有被调用。
release objects in viewDidUnload/viewDidDisappear and set to nil in dealloc
this might work, but you should surely look why viewWillDisappear is not called.