Search code examples
cocoa-touchxcode4iboutlet

Xcode: Create a group of outlets


This is just a quick question, I have lots of outlets in my code that need to be hidden initially and I want to make it so that in my viewDidLoad I only have to say something along the lines of colourObjects.hidden = YES; rather than individually going through and declaring if they are hidden or not i.e. redColourObject.hidden = YES; blueColourObjects.hidden = YES; greenColourObjects.hidden = YES; I would find it very grateful to know if this is possible and how you do it!

Thanks for any help Hugh


Solution

  • IBOutletCollection is what you need:

    @property (nonatomic, strong) IBOutletCollection(UIView) NSArray *stuff;
    

    You can drag as many outlets as you want in it and they'll be there. You can also keep the original references for other purposes. then

    for (UIView *view in self.stuff) {
        [view setHidden:YES];
    }