如果 UIAcivityIndicatorView 被删除/释放/解除分配,它是否会自行停止动画
我在表格单元格的accessoryView 中使用UIActivityIndicator。实际上它是 anotherView (单元格的accessoryView)的子视图,如下所示:
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[anotherView addSubview:activityIndicator];
[activityIndicator startAnimating];
[activityIndicator release];
cell.accessoryView = anotherView;
对于我的用例,我不需要再访问指示器视图。另外,如果完整的视图将被删除(由于取消 ViewController),我不关心那些 UIActivityIndicators。
那么这种类型的使用是否安全并且不会产生任何内存/资源剩余?我已经检查过,UIActivityIndicatorView
的 dealloc
被调用(确实如此),所以我假设动画也会在视图层次结构被销毁时自动停止/删除。
我的假设正确吗?
I am using UIActivityIndicator within a table cell's accessoryView. Actually it is a subview of anotherView (which is the cell's accessoryView) as seen below:
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[anotherView addSubview:activityIndicator];
[activityIndicator startAnimating];
[activityIndicator release];
cell.accessoryView = anotherView;
For my use case, I do not need to access the indicator view any more. Also if the complete view will be removed (due to dismissing the ViewController), I am not caring about those UIActivityIndicators.
So will this type of usage be safe and not create any memory/resource leftovers? I have checked, that dealloc
of UIActivityIndicatorView
is called (and it is), so I would assume the animation will be stopped/removed automatically as well while the view hierachy is destroyed.
Is my assumption correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,一旦您放弃了指标的所有权,视图层次结构仍然是唯一的所有者。如果从视图层次结构中删除父视图并且没有在其他地方保留该父视图,则该父视图将释放其所有子视图。如果子视图的保留计数为零,则它们将被释放。这就是您的指标视图所发生的情况。
Yes, once you've relinquished ownership of the indicator, the view hierarchy remains the only owner. If a superview is removed from the view hierarchy and if it is not retained elsewhere, the superview releases all its subviews. If the subviews hit a retain count of zero, they are deallocated. This is what is happening with your indicator view.