Using Interface Builder Tags

I use the interface tag function to access some UILabels that I create in the xib file. Since this is a UITextViewCell, I want to avoid unnecessary method calls, but I also want to do it right. Thus, when I do this:

UILabel *label = (UILabel *)[cell viewWithTag:1]; 

I am wondering if I need to wrap it like this:

 if([[cell viewWithTag:1] isKindOfClass [UITableViewCell class]]) { UILabel *label = (UILabel *)[cell viewWithTag:1]; } 

Any discussion on this issue would be appreciated.

thanks

+3
source share
4 answers

If you have many different objects of different classes that have subviews with tags '1', then this is optional.

If you have a bunch of different objects (cells, say) that have different classes, but all have subitems with tag 1, I would rethink your tag scheme. Perhaps 101, 201 and 301, etc.

+3
source

As in August, I suggest making your tag numbers unique in this thread of your presentation hierarchy.

I also suggest that you configure enum to list your possible tag values ​​so that your viewWithTag: method viewWithTag: more readable.

+6
source

Yes, I find that the enum method works well or just #define foo 1, #define bar 2, etc.

+1
source

You set tags in the interface builder using command-1 in the attribute editor and see the "tag" under the background setting.

+1
source

All Articles