iphone uiimage 标签 - 可以使用字符串吗?
简单的问题...
我有一系列按钮,每个按钮都有一个标签。我单击根据标签号单独创建 uiimageview 的按钮。所以这个标签号,比如 43 被传递,并使用 43.png 创建一个新的 uiimageview
所有这些都运行良好,我可以通过单击它们来删除创建的图像...
..但是...我现在想知道如何我可以一次性删除所有这些创建的图像。所以我说 4 个图像都是通过单击按钮创建的。
我的问题是:我可以使用字符串来识别这些“创建的”图像吗?我考虑过为他们使用一个以 99 开头的标签吗?所以 991、992、993 等等,但这似乎不是一个好的编码。过去,实际上在 Flash 中,我使用了 item1、item2 标签...然后在代码中,我只需循环遍历屏幕上以“item”开头的所有标签并将其删除。
关于解决这个问题的最佳方法有什么想法吗?
谢谢
quick question...
I have a series of buttons, each with a tag. I click the buttons which individually create a uiimageview based on the tag number. So this tag number, say 43 is passed and a new uiimageview is created using 43.png
All this is working nicely and I can remove the created images by clicking on them...
..but... I'm now wondering how I can remove all these created images all at once. So I have say 4 images which were all created as a result of clicking the buttons.
my question is this: can I use a string to identify these "created" images some how? I thought about using a tag for them starting with 99 maybe? so 991, 992, 993 etc. but this doesn't seem like good coding. In the past, and indeed in Flash, I used a tag of item1, item2... then in the code, I simply loop through ALL tags on the screen starting with "item" and remove them.
any ideas on the best way to tackle this??
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以简单地将对所有创建的图像的引用存储为数组中的元素,并将其作为 viewController 的属性保存。
或者,这种问题可以用子类来处理。您可以使用某种标识符属性创建 UIImage 的子类,然后使用它来删除它们。
You could simply store a reference to all the created images as elements in an array kept as an attribute of the viewController.
Alternatively, this is the sort of problem that can be handled with a subclass. You can just create a subclass of UIImage with some sort of identifier attribute and use that to remove them.
似乎您可以循环遍历
subviews
数组,查看每个视图的tag
属性,将每个属性转换为字符串,然后使用NSStringstartsWith: 删除那些与您的模式匹配的内容。
但我认为保留自己创建的图像列表并在需要时删除它们会更容易。
Seems like you could just loop through the
subviews
array, look at thetag
property of each one, convert each to a string, and useNSString startsWith:
to remove those that match your pattern.But I think it would be easier to just keep your own list of created images, and delete them when desired.