view will disappear is not firing

冷暖自知 提交于 2020-01-04 09:37:07

问题


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.


回答1:


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().




回答2:


You can try to release objects in method viewDidDisappear. Then you won't wait for firing method dealloc.

Also in method viewDidDisappear you can try to remove all subviews from superview (that will call viewWillDisappear to all subviews):

NSArray *subviews = [self.view subviews];
for (UIView *view in subviews)
    [view removeFromSuperview];



回答3:


release objects in viewDidUnload/viewDidDisappear and set to nil in dealloc

this might work, but you should surely look why viewWillDisappear is not called.



来源:https://stackoverflow.com/questions/7279705/view-will-disappear-is-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!