Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Interface Builder tags

I'm using interface builder's tag feature to access some UILabels I'm instantiating in a xib file. Since this a UITextViewCell I want to avoid superfluous method calls, but I want to do it right too. Thus when I do:

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

I'm wondering if I should wrap it up like so:

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

Any discussion on this would be appreciated.

Thanks

like image 758
pat Avatar asked Sep 20 '26 09:09

pat


2 Answers

Like August, I'd suggest making your tag numbers unique within that branch of your view hierarchy.

I'd also suggest that you set up an enum to enumerate your possible tag values so that your viewWithTag: method becomes more readable.

like image 137
Ashley Clark Avatar answered Sep 22 '26 23:09

Ashley Clark


Unless you have a lot of different objects of different classes that have subviews tagged '1' then this isn't necessary.

If you DO have a bunch of different objects (cells, say) that have different classes but all have subviews with a 1 tag, I'd reconsider your tagging scheme. Perhaps 101, 201, & 301, etc.

like image 24
August Avatar answered Sep 22 '26 22:09

August



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!