如何使用NSString设置UIButton标记? [英] How to set a UIButton tag with NSString?
本文介绍了如何使用NSString设置UIButton标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 UIButton
中是否有其他属性,如标记
,我可以用来存储 NSString
?
Is there another property like tag
in UIButton
where I can use to store NSString
?
我知道标签
是一个int所以我无法存储 @ myvalue的
。我想知道是否有其他方法可以做到这一点。
I know tag
is an int so I can't store @"myValue"
. I was wondering if there are other ways to do this.
推荐答案
不,没有类似于<$ c $的东西c>标记带有NSString。
No, there isn't anything similar to tag
that takes an NSString.
请注意,如果您只想要一个描述性标记,则枚举可能很有用。
Note that if you just want a descriptive tag, an enum can be useful.
enum ButtonTypes {
ButtonTypeUnknown,
ButtonTypeOK,
ButtonTypeFoo,
ButtonTypeBar,
// etc...
};
稍后......
switch (mybutton.tag) {
case ButtonTypeFoo:
// handle this button type
break;
case ButtonTypeBar:
// handle this button type
break;
default:
break;
}
这篇关于如何使用NSString设置UIButton标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文