Search code examples
iosiphoneinterface-builderiboutletiboutletcollection

How to make IBOutlets out of an array of objects?


I want to make an array with a bunch of UIImageViews I have in Interface Builder. Instead of having 20 or 30

IBOutlet UIImageView *img1;

and linking them all that way, and then putting them into an array, is there a way to declare an array of IBOutlet UIImageViews?

Just so I don't have so many declarations in my header file.


Solution

  • It is possible, it’s called outlet collection. This is the way to define an outlet collection:

    @property(retain) IBOutletCollection(UIImageView) NSArray *images;
    

    Now you can stick more than one object into the outlet in the Interface Builder, the array will be created for you when the interface is loaded.