iPhone:如何从 UIScrollView 中删除所有对象
基本上我想从 UIScrollView 中删除所有对象,但我还没有找到解决方案,因为简单的“removeAllObjects”命令不起作用。有人知道该怎么做吗?
Basically I want to remove all objects from a UIScrollView and I haven't yet found a solution to it because a simple "removeAllObjects" command doesn't work. Does anyone have an idea how to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更简单:
Even easier:
最简单的方法:
The easiest way:
在不删除滚动条的情况下,有两种解决方案:
向所有子视图添加标签,然后使用这些标签删除它们。
实现:
将其放在类上方
当您添加对象时
当您稍后想要删除视图时 使用
创建一个自定义 UIView 类
当您想要删除视图时
Two solutions would be, without removing the scrollbars:
Add a tag to all of your subviews, remove them by using those tags.
Implementation:
Place this above your class
When you add the objects
When you later want to delete the views use
Create a custom UIView class
When you want to remove the views
Oritm 的解决方案很好,但是如果您不想使用标签,您可以手动删除要从滚动视图中删除的视图。这将假设您知道要删除哪个视图。例如,我的滚动视图只有 UILabels,因此当我运行以下命令时:
这只会删除所有标签,但保留滚动条(它们是图像视图)。注意:如果您想保留特定的图像视图,同时又想保留滚动条,则此方法将不起作用。
Oritm's solution is nice, but if you don't want to bother using tags, you can manually remove which views you want to remove from the scrollview. This will assume that you know which view to remove. For example, my scrollview only has UILabels so when I run the following:
This will only remove all the labels but keep the scrollbars (which are image views). Note: this won't work if you want to keep specific image views while at the same time you want to keep the scrollbars.