swiftxcodeuicollectionviewcellcollectionviewoutlet

I can't create an outlet for a label in my collection view cell


So everything is done the way you would assume. I drag and drop a collection view into a controller view. I connect the datasource and delegate. blah blah blah everything is done by the book.

Ok so i want to connect a label inside my collectionViewCell to my viewController class. I use control+drag to drop it into my code and type in its name.

As soon as i hit connect, i get a red octagonal error. it says: "Illegal Configuration: The hoursPerDayOutlet outlet from the monthCellViewController to the UILabel is invalid. Outlets cannot be connected to repeating content."

I need to connect this though because as each cell is created it will have a different label.

Please help me fix and use swift. All advice is appreciated. Thanks!

enter image description here


Solution

  • You can't connect items inside a UICollectionViewCell to a UIViewController, create a UICollectionViewCell subclass, make the class of the cell to the subclass and then you can connect the items inside the cell to the subclass (not the controller). I recommend you to look at more tutorials on UICollectionView.