3

I try to do something like this @IBoutlet var buttons : [UIButton]

but I can't drag button to this outlet

Any idea, how can I achieve that?

Krunal
  • 77,632
  • 48
  • 245
  • 261
motivated
  • 53
  • 8
  • https://stackoverflow.com/questions/8564249/can-i-connect-multiple-objects-with-different-tags-to-the-same-iboutlet – iPatel Oct 13 '17 at 13:35

2 Answers2

6

It's possible to do that.

Here is how:

  • Create an array of IBOutlets
  • Add multiple UIElements (Views) in your Storyboard ViewController interface
  • Select ViewController (In storyboard) and open connection inspector
  • There is option 'Outlet Collections' in connection inspector (You will see an array of outlets there)
  • Connect if with your interface elements

-

class ViewController2: UIViewController {


    @IBOutlet var collection:[UIView]!


    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

enter image description here

Krunal
  • 77,632
  • 48
  • 245
  • 261
1

To add a button to an existing array outlet, drag the other way 'round: from the circle in the margin of the view controller to the button. (No need to hold the control key while doing this drag.)

leanne
  • 7,940
  • 48
  • 77