0

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

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

Simon Whitaker
  • 20,506
  • 4
  • 62
  • 79
Arcadian
  • 4,312
  • 12
  • 64
  • 107

2 Answers2

3

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...
};

Then later...

switch (mybutton.tag) {
    case ButtonTypeFoo:
        // handle this button type
        break;
    case ButtonTypeBar:
        // handle this button type
        break;
    default:
        break;
}
Simon Whitaker
  • 20,506
  • 4
  • 62
  • 79
2

I ended up subclassing the UIButton and added the property I wanted. That was easy enough.

Arcadian
  • 4,312
  • 12
  • 64
  • 107