如果 UIAcivityIndi​​catorView 被删除/释放/解除分配,它是否会自行停止动画

发布于 2024-11-10 01:00:17 字数 677 浏览 0 评论 0原文

我在表格单元格的accessoryView 中使用UIActivityIndi​​cator。实际上它是 anotherView (单元格的accessoryView)的子视图,如下所示:

UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] 
    initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[anotherView addSubview:activityIndicator];
[activityIndicator startAnimating];
[activityIndicator release];
cell.accessoryView = anotherView;

对于我的用例,我不需要再访问指示器视图。另外,如果完整的视图将被删除(由于取消 ViewController),我不关心那些 UIActivityIndi​​cators。

那么这种类型的使用是否安全并且不会产生任何内存/资源剩余?我已经检查过,UIActivityIndi​​catorViewdealloc 被调用(确实如此),所以我假设动画也会在视图层次结构被销毁时自动停止/删除。

我的假设正确吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮邮递员 2024-11-17 01:00:17

是的,一旦您放弃了指标的所有权,视图层次结构仍然是唯一的所有者。如果从视图层次结构中删除父视图并且没有在其他地方保留该父视图,则该父视图将释放其所有子视图。如果子视图的保留计数为零,则它们将被释放。这就是您的指标视图所发生的情况。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文