chauhan1009
chauhan1009

Reputation: 1

How to set string value in button's tag

I wanted to give a string value to UIButton tag for unique identities. but button tag do not understand string valve, it is replace into intger value.

Upvotes: 0

Views: 435

Answers (3)

AMayes
AMayes

Reputation: 1767

Alternatively, you can subclass UIButton, and declare a NSString variable in the .h file.
@property (nonatomic, strong) NSString *tagString; You can then either set your buttons' class in Storyboards, or in code, and tag them with your strings by assigning that value. Otherwise, use typedef enum.

Upvotes: 0

Stefan Fisk
Stefan Fisk

Reputation: 1573

The tag property is an int, and will not take a string.

However, you can create an enum, and then set the tags appropriately.

typedef enum : int {
    Tag1 = 1,
    Tag2
} MyTag;

...

view.tag = Tag1;

Upvotes: 0

Alexander
Alexander

Reputation: 8147

UIView's tag property is of NSInteger type, so you can't place a string there. There are ways you can circumvent this, though (lookup tables, etc).

Upvotes: 1

Related Questions