setNeedsDisplay 释放子视图?

发布于 2024-11-17 09:52:04 字数 298 浏览 3 评论 0原文

如果自定义视图根据条件if向自身添加多个子视图,并且稍后在条件不再truesetNeedsDisplay code> 因此这些子视图没有被创建,“旧”子视图是否在drawRect期间自动从内存中释放?

或者,我是否应该担心检查子视图是否存在,释放它们,然后setNeedsDisplay?

我想最终我的问题是关于 setNeedsDisplay 的内存影响,如果它有效地从内存中删除旧视图及其子视图,然后从头开始重新创建视图?

If a custom view adds several subviews to itself based on a condition if, and later a setNeedsDisplay is called on this view where the condition is no longer true and thus these subviews are not created, are the "old" subviews automatically released from memory during the drawRect?

Or, should I worry about checking for the presence of subviews, releasing them, then setNeedsDisplay?

I guess ultimately my question is about the memory implications of setNeedsDisplay, if it effectively removes from memory the old view and its subviews and then essentially recreates the view from scratch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

棒棒糖 2024-11-24 09:52:04

-setNeedsDisplay 只是设置一个标志,表示“此视图需要重绘”。据我所知,它不会保留或释放任何内容,也不会添加或删除任何子视图。

我不确定你想做什么,但听起来你担心太多了。当应用程序的状态发生变化,需要重新绘制给定视图时,请调用 -setNeedsDisplay。如果您随后从视图层次结构中删除该视图,则不会导致任何问题。

-setNeedsDisplay just sets a flag that says "this view needs to be redrawn." As far as I know, it doesn't retain or release anything, or add or remove any subviews.

I'm not sure what you're trying to do, but it sounds like you're worrying too much. Call -setNeedsDisplay when your app's state has changed in a way that requires a given view to be redrawn. If you subsequently remove that view from your view hierarchy, that shouldn't cause any problem.

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