Passing multiple tags with UIButton(使用 UIButton 传递多个标签)
问题描述
好的,我有一个具体的情况.我正在使用自定义类来创建一些按钮,我可以使用唯一的数字设置它们的标签属性,例如:
OK I have a specific situation. I am using a custom class to create some buttons and I can set their tag property with unique numbers like:
button.tag =[NSNumber numberWithInt:[10]];
这在我程序的另一部分非常有用,因为我可以访问这个独特的标签,例如:
This is very useful in another part of my program because I can access this unique tag like:
UIButton *clicked= (UIButton *) sender;
ButtonTag = [NSString stringWithFormat:@"%d", clicked.tag];
现在我想再传递一个像这样的独特属性.我正在编造这个,但这就是我的设想
Now I want to pass one more unique property just like this. I am making this up but this is how I envision it
button.tagCREATED_BY_ME =[NSNumber numberWithInt:[9000]];
这个问题可能措辞不好,但我不知道更好,所以我称之为标签".(正确的措辞可能是元素/属性等)我如何创建一个类似的属性来像 .tag 一样发挥作用?
The question might be poorly worded but I don't know any better so I called it "tag".(correct wording might be element/property etc) How do I create a similar property to function just like .tag?
非常感谢!阿尔达
推荐答案
在你的子类/自定义按钮中,你可以添加一个字符串属性,甚至是一个整数属性,只要你觉得好.
In your subclassed/custom button, you can add a string property or even an integer property whichever you feel good.
@interface CustomButton: ....
...
@property(strong) NSString *createdBy;
@end
然后你可以访问那些 aButton.createdBy
Then you can access those as aButton.createdBy
这篇关于使用 UIButton 传递多个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 UIButton 传递多个标签


基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01