Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Referencing outlet collection in Xcode4 Interface Builder?

enter image description here

Here, I have pointed to the Referencing Outlet Collection. I am not able to figure out its usage in XCode4.

I am asking for the `new feature of REFERENCING OUTLET COLLECTION in InterfaceBuilder of XCode4".

like image 245
Sagar Kothari Avatar asked Jul 11 '11 11:07

Sagar Kothari


People also ask

What is outlet in Swift?

An outlet is a property that is annotated with the symbol IBOutlet and whose value you can set graphically in a nib file or a storyboard. You declare an outlet in the interface of a class, and you make a connection between the outlet and another object in the nib file or storyboard.

What is IBOutletCollection?

As the name says, an IBOutletCollection is a collection of IBOutlets . It can either be a collection of UI elements. An IBOutletCollection of UIButton in code will look like this: @IBOutlet var starButtons: [UIButton]! It will be an array of UIButton objects.


1 Answers

The IBOutletCollection is a way to group IBOutlets. Imagine that you have 3 or 4 UILabels, on which you will apply a style (font, backgroundColour, opacity, etc). With a IBOutletCollection, it becomes trivial to do this. First you need to define your IBOutletCollection:

@property (nonatomic, retain) IBOutletCollection(UILabel) NSArray *labelsCollection; 

(notice the type we are putting inside parenthesis, although we could put an id, if we had a mix collection)

Connect the IBoutlets on Interface Builder and then just iterate it:

for(UILabel *label in labelsCollection) {     // Apply your styles } 

Hope this helps you understand:

http://useyourloaf.com/blog/2011/3/28/interface-builder-outlet-collections.html

like image 147
Rui Peres Avatar answered Sep 27 '22 20:09

Rui Peres