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.
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?
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.
This may cause a problem when you will try to perform some operations on the label text data.I would suggest you to have a look at IBOutlet Collections
.You can find nice tutorial here.
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