I have a view controller and two views. I have an outlet called name. I connect the outlet to a label on the first view and the value appears fine. I have another label on the second view. When I connect it to the name outlet, the connection on the first view is broken.
Any thought?
Thanks
Martin
You can't attach more than one label to an outlet, but you can attach more than one label to an outlet collection. It's the same idea as an outlet, but instead of having one label (or view) you have an array. The procedure is the same for creating regular outlets, but you just drag from the section in the Connections Inspector under "Referencing Outlet Collection". The first time you do that, an array will be created to manage your outlet collection. Then, every time after that you just connect your other labels (or views) to that same collection.
No, you cannot connect multiple objects to a single IBOutlet. The right way to handle 2 different objects is to create two outlets in your view controller
@IBOutlet weak var nameInView1: UILabel!
@IBOutlet weak var nameInView2: UILabel!
And connect each outlet to the appropriate label.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With