是否可以在 uiimageview 中单独标记 uiimage? [英] Is it possible to tag a uiimage in uiimageview individually?

查看:30
本文介绍了是否可以在 uiimageview 中单独标记 uiimage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIImageView 和 UIImage 的类参考中搜索,但没有找到任何关于标记的信息.

I searched in the class reference of UIImageView and UIImage, but did not find any info on tagging.

在我的代码中,我为 UIImageView 标记了 NSMutableArray 图像中的所有图像,以便稍后检索标记:

In my code, I tagged all of the images in my NSMutableArray of images for my UIImageView, so I could retrieve the tag later:

[[images objectAtIndex:0] setTag:1];
[[images objectAtIndex:1] setTag:2];
[[images objectAtIndex:2] setTag:3];
...

这会导致我的应用程序在运行时崩溃.

This causes my application to crash when I run it.

输出如下:

2013-08-08 11:26:48.596 Tap Me[8145:c07] -[UIImage setTag:]:无法识别的选择器发送到实例 0x752e820 2013-08-08 11:26:48.595:Tap Me[8714]*终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因是: ' - [UIImage的setTag:]:无法识别的选择发送到实例0x752e820' *第一掷调用堆栈:(0x1c92012 0x10cfe7e 0x1d1d4bd 0x1c81bbc 0x1c8194e 0x2d5c 0xf51c7 0xf5232 0x100c25 0x3003a3 0xfdee3 0xfe167 0xfe1a7 0x46a0a2 0x45bb990x45bc14 0x10e3705 0x172c0 0x17258 0xd8021 0xd857f 0xd76e8 0x46cef 0x46f02 0x24d4a 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1bec7e3 0x1bec668 0x13ffc 0x267d 0x25a5)的libc ++ abi.dylib:终止称为抛出异常(LLDB)

2013-08-08 11:26:48.596 Tap Me[8145:c07] -[UIImage setTag:]: unrecognized selector sent to instance 0x752e820 2013-08-08 11:26:48.597 Tap Me[8145:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage setTag:]: unrecognized selector sent to instance 0x752e820' * First throw call stack: (0x1c92012 0x10cfe7e 0x1d1d4bd 0x1c81bbc 0x1c8194e 0x2d5c 0xf51c7 0xf5232 0x100c25 0x3003a3 0xfdee3 0xfe167 0xfe1a7 0x46a0a2 0x45bb99 0x45bc14 0x10e3705 0x172c0 0x17258 0xd8021 0xd857f 0xd76e8 0x46cef 0x46f02 0x24d4a 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1bec7e3 0x1bec668 0x13ffc 0x267d 0x25a5) libc++abi.dylib: terminate called throwing an exception (lldb)

我稍后需要访问当前在 UIImageView 中显示的图像的标签是否具有 10 或更少或 10 以上的标签:

I later need to access whether the tag of the image currently being displayed in UIImageView has a tag of 10 or less, or above 10:

 if ((picImageView.tag<=10 && [[sender currentTitle]isEqual:@"soap"])||    (picImageView.tag>10 && [[[sender titleLabel] text]isEqual:@"cheese"]))
    {
        count++;
        [picImageView setImage:[images objectAtIndex:arc4random()%imageNames.count]];
    }
else
    {
        [picImageView setImage:[images objectAtIndex:arc4random()%imageNames.count]];
    }

我是目标 c 的新手.如果有人可以回复显示如何向 UIImage 添加标签的代码,那将对我有很大帮助.预先感谢您,并为这个愚蠢的问题感到抱歉.

I am new to objective c. If anyone could reply with code showing how to add a tag to a UIImage, that would help me greatly. Thank you in advance and sorry for the silly question.

推荐答案

这听起来像是一个糟糕的设计,我建议使用您的标识属性(int 或 NSString 或任何您想要的)扩展 UIImage 并在您的设备上使用它时检索此属性NSMutableArray.

That sounds like a bad design, I suggest extend UIImage with your identification property (int or NSString or whatever you want ) and retrieve this property when using it on your NSMutableArray.

这种方法有效而且很干净

This approach works and it is clean

这篇关于是否可以在 uiimageview 中单独标记 uiimage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆