Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 335
Marty Avatar asked Dec 05 '10 00:12

Marty


People also ask

What is IBOutlet and IBAction?

@IBAction is similar to @IBOutlet , but goes the other way: @IBOutlet is a way of connecting code to storyboard layouts, and @IBAction is a way of making storyboard layouts trigger code. This method takes one parameter, called sender . It's of type UIButton because we know that's what will be calling the method.

What is Iboutlets?

An IBOutlet helps connect the object control to the code to make the object accessible via the program. IBOutlet makes the connection between the declared instance variables wit the elements in the prototype cell. It typically holds these other objects as properties backed by instance variables.


1 Answers

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.

like image 132
zoul Avatar answered Sep 23 '22 06:09

zoul