user2636197 user2636197 - 1 year ago 100
Swift Question

Swift ios connect multiple items to the same IBOutlet

I wonder if its OK to connect multiple items to the same IBOutlet?
In my tableView I have setup two cells and given them a uniqe identifier.

But I have connected the label in each cell to the same IBOutlet in my custom UITableViewCell class.

enter image description here

class SearchSubCatTableViewCell: UITableViewCell {

@IBOutlet weak var subCatTitle: UILabel!

So I have two labels connected to
@IBOutlet weak var subCatTitle: UILabel!

This all works fine when I am testing the app but can it cause any problems?

Answer Source

Yes, this is ok as long as you don't plan on doing any operations on those labels.

The correct way to do it, is by creating an array IBOutlet:

@IBOutlet var collectionOfLabels:[UILabel]?
  • Connect all your labels to this labels array outlet.

  • Then access the labels via the array.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download