How to make IBOutlets out of an array of objects?

Marty picture Marty · Dec 5, 2010 · Viewed 10.6k times · Source

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.

Answer

zoul picture zoul · Jan 12, 2011

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.