Animations make my app crash: How can I remove them?
In my app, I create view controller objects as I need them. When a view controller goes away, I get rid of it by calling -removeFromSuperview on it's view and then set the retaining property to nil.
That way my app uses very low memory all the time. But there's a problem: I have heavy animations going on in some view controllers, and every animation always has an animation delegate which is self. Now the thing that happens is: When there are animations running and I drop the view control开发者_开发知识库ler, it goes away - and at some point when one of those animations finishes it seems to crash.
So the question is: How to remove any running animation from a view and all it's subviews?
Agreed. There may be some confusion on how you add/remove the subview, and how you retain/release it. Make sure that you are following these guidelines:
// To add
AView * aSubView = [[AView alloc] init];
[aContainerView addSubview:aSubView];
[aSubView release]; // aSubView is retained by aContainerView
... and later on
// To remove
[aSubView removeFromSuperview]; // and nothing else!
Do not do this:
[self removeFromSuperview]; // Don't cut the branch on which you are sitting
(you already knew that!)
精彩评论