Is it possible to use something like an IBOutlet array?

I have the top list in my current iPhone app filled with code. I put together a view using Interface Builder, so it contains a lot of UILabel s.

Obviously, I would not want to have name1 , name2 , etc. in my class, but I prefer the array name[10] .

Is it possible to do this and associate each element with a corresponding label (or any other interface builder, for example, a view)?

+4
source share
4 answers

you cannot do this in IB, but you can create an array in your init method and add all your labels to it.

By the way, you can set a tag on each label and define a macro to access it. smth like

 #define NAME[TAG] (UILabel*)[self.view viewWithTag:TAG] 
0
source

You can, of course, do this using the interface builder, the IBOutletCollection keyword. What he does is basically an NSArray of several interface builders.

 IBOutletCollection(UILabel) NSArray *myLabels; 

So, the next thing will be related to your labels in the interface builder, and then you can use an array to access all the labels at runtime.

+22
source

This can be done using alumni collections; see this related question .

0
source

Follow these steps to create an array of outputs by connecting them to IB Elements (here is an example of a UIView , you can also use UILabel ):

  • Create an IBOutlets Array
  • Add multiple UIElements (Views) in your ViewController interface for storyboard
  • Select ViewController (in storyboard) and Open Connector Inspector
  • In the connection inspector there is the option “Outlet Collections” (you will see an array of outlets there)
  • Connect if with interface elements

-

 class ViewController2: UIViewController { @IBOutlet var collection:[UIView]! override func viewDidLoad() { super.viewDidLoad() } } 

enter image description here

0
source

All Articles