How to connect 3 UIButton to one outlet

只愿长相守 提交于 2019-12-23 19:13:38

问题


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?


回答1:


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()
    }
}




回答2:


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.)



来源:https://stackoverflow.com/questions/46731185/how-to-connect-3-uibutton-to-one-outlet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!