Arcadian
Arcadian

Reputation: 4350

How to set a UIButton tag with NSString?

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.

Upvotes: 0

Views: 1813

Answers (2)

Arcadian
Arcadian

Reputation: 4350

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

Upvotes: 2

Simon Whitaker
Simon Whitaker

Reputation: 20586

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

Upvotes: 3

Related Questions