Practical effective use of IBOutletColletion

What does the practical use of IBOutletCollection look like? Unfortunately, Apple's documentation mentions it briefly, without giving a broader view of usage. Well, he maintains a one-to-many relationship with IB, but how to effectively access and use specific objects? With TagName? How to ensure the order of objects?

+5
source share
3 answers

I recently used this to easily initialize a label grid. I have the nth matrix of labels on the view, and refer to each other individually (via IBOutlet) to display the corresponding data. However, when the views are loaded first, I would like to control the default text displayed in all the shortcuts. I initially wanted to display a dash, but since this is for the client, I wanted it to be easy to change. The content of the presentation has and continues to change over time, for each client request.

Instead of writing N lines of code, I created an IBOutletCollection and performed the same results in 4 (@property, @synthesize and for the loop). YMMV, but I found it very useful in this situation.

+5
source

Interface Builder.

IBOutletCollection NSArray IB. , , , .

0

. UIViews, " " UIButtons ( ).

UIButtons (, 1005 1010), UIViews , UIButton, .

Then I linked UIViews to the collection in Interface Builder. All UIButton events are in contact with the same function in my controller. This function gets the tag of the sender object, iterating through the NSArray ("IBOutletCollection (UIView)") list and compares the tag. Each time it hits, the corresponding action is performed.

Too bad NSArrays doesn't seem to keep order ...

0
source

All Articles