How to set a UIButton tag using NSString?

Is there another property like tag in UIButton where I can use NSString to store?

I know tag is an int, so I cannot store @"myValue" . I was wondering if there are other ways to do this.

0
source share
2 answers

No, nothing looks like a tag that accepts an NSString.

Note that if you just want a descriptive tag, an enumeration may be useful.

 enum ButtonTypes { ButtonTypeUnknown, ButtonTypeOK, ButtonTypeFoo, ButtonTypeBar, // etc... }; 

Then later ...

 switch (mybutton.tag) { case ButtonTypeFoo: // handle this button type break; case ButtonTypeBar: // handle this button type break; default: break; } 
+3
source

I ended up subclassing UIButton and adding the property I wanted. It was easy.

+2
source

All Articles