iPhone SDK 管理多视图应用程序的内存
我有一个应用程序,可以根据文本文件的内容以编程方式创建标签和文本字段。每当加载视图控制器时,它都会创建每次都不同的文本字段和标签。我的问题是我需要清除标签和文本字段而不释放视图控制器,因为我需要跟踪视图控制器。我尝试了 self.viewController = nil,但我很确定这会导致内存泄漏。有没有办法删除视图的所有子视图?
I have an app that programmatically creates labels and text fields based on the contents of a text file. Whenever the view controller is loaded, it creates text fields and labels that are different each time. My problem is I need to clear out the labels and text fields without releasing the view controller since I need to keep track of the view controller. I tried self.viewController = nil
, but I'm pretty sure this results in a memory leak. Is there a way to delete all the subviews of a view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Greg 的意思是这样的:
但这可能不会像您期望的那样工作,因为 Objective C 不喜欢在 for 循环中迭代数组时修改数组。更安全的选择是这样的:
What Greg meant to say is this:
This may not work as you would expect though, as Objective C doesn't like it when you modify an array while you're iterating through it in a for loop. A safer choice would be this:
如果您有一个名为
view
的视图,您应该能够使用以下代码从视图中删除所有子视图:If you have a view named
view
, you should be able to remove all of the subviews from the view using this code: