How to hide a bunch of labels in an IBOutletCollection?
-
11-06-2021 - |
Question
New to Objective-C and iOS development, would love a hand here!
I have written up some code such that
IBOutletCollection(UILabel) NSArray *allLabels;
In IB I have linked up all my labels in my view to this collection, where I want to hide them for a certain condition. However, I am not sure how to do so. Obviously to hide a single label I'd use
labelX.hidden = YES;
however it is not ideal for me to do this without a collection, as I have many labels to hide.
Thanks for your tips in advance!
Solution
try this...
[allLabels setValue:@(YES) forKey:@"hidden"];
OTHER TIPS
Just enumerate collection and do whatever you want with contents:
[allLabels enumerateIndexesUsingBlock:^(UILabel *label, NSUInteger idx, BOOL *stop) {
label.hidden = YES;
}];
Swift Version for Array type:
(allLabels as NSArray).setValue(NSNumber(bool: true), forKey: "hidden")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow