Reputation: 452
Xcode 9.2, Swift 4. For a cell in a Collection View Controller, I created a subclass named CollectionViewController. I linked the cell to this subclass. I created a Label in the cell on the Main.storyboard and linked it to the subclass like this :
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var personName: UILabel!
}
Then i try to access to this label in the collectionView function inside my CollectionViewController class, subclass of UICollectionViewController, which is linked to the Collection View Controller where my cell is :
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! CollectionViewCell
cell.personName.text = "text"
return cell
}
That's how i have this error : "The personName outlet from the UICollectionView to the UILabel is invalid. Outlets cannot be connected to repeating content."
Upvotes: 1
Views: 2258
Reputation: 1
solution: From viewcontroller
kindly remove the IBoutlet of colllectionviewcell
. the issue mentions the invalid of your IBOutlet. so remove all subclass which has multi-outlet(invalids) and reconnect it.
The answer is already mentioned in another question
Upvotes: 0
Reputation: 3
Additional note for similar error condition:
In the error message I got, along with the message similar to above, Xcode(ver 12.0) also provided the Object ID
, which I referred to in the Identity Inspector tab
to eradicate the cause of the error.
Upvotes: 0
Reputation: 437702
I'd suggest you double check the "connections inspector" (the last tab on the panel on the right) for that control (and any other controls inside that cell). It sounds like something in the cell has a lingering outlet hooked up to the view controller. The connections inspector will help you identify that:
Make sure the view controller doesn't show up as one of the outlets. In the above example, I have "accidentally" created two outlets for this label, one to the cell subclass (which is correct) and one to the view controller (which is incorrect).
That will result in a compile-time error that says:
error: The customLabel outlet from the ViewController to the UILabel is invalid. Outlets cannot be connected to repeating content.
If you delete the outlet connection between the cell and the view controller (or whatever non-cell class it's hooked up to), and this compile-time error will go away.
Note, the sentence before the "Outlets cannot be connected to repeating content" message will tell you precisely which outlet is causing the problem. You can even click on this error inside the "issues navigator" in the left panel and Xcode will jump to the storyboard and select the offending control (at which point you can directly open up the connections inspector) and find the offending outlet.
Upvotes: 1