Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify view with NSString tag?

view.tag is only stored NSInteger Value.

so, how to identify each view with NSString Value?

not avaliable?

some example:

view0.stringTag = @"basic";

view1.stringTag = @"advanced";
like image 489
bitmapdata.com Avatar asked Nov 29 '22 17:11

bitmapdata.com


1 Answers

There's no stringTag property on UIView. If you need to do this kind of thing you can use a category on UIView and store the tag in an associated object:

@interface UIView (StringTagAdditions)
@property (nonatomic, copy) NSString *stringTag;
@end

@implementation UIView (StringTagAdditions)
static NSString *kStringTagKey = @"StringTagKey";
- (NSString *)stringTag
{
    return objc_getAssociatedObject(self, kStringTagKey);
}
- (void)setStringTag:(NSString *)stringTag
{
    objc_setAssociatedObject(self, kStringTagKey, stringTag, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
@end
like image 167
Nikolai Ruhe Avatar answered Dec 01 '22 06:12

Nikolai Ruhe