-1

I have a custom UICollectionViewCell defined in a .xib that is connected to a custom class file. I am able to register and display this empty cell in a collection view. I'm even able to set values for the cell like background color in the awakeFromNib function in the custom class. As soon as I add a label (myLabel) to the cell in the xib and make an outlet for it in its custom class file, I get a "this class is not key value coding-compliant for the key myLabel" crash when I run. What is causing this?

I searched through the suggested duplicate question and wasn't able to find a cause there. I think the problem may have more to do with my xib containing a UICollectionViewCell instead of a UIView. Perhaps I'm missing something that requires special attention when setting this up.

  • Possible duplicate of [What does this mean? "'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X"](https://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key-v) – Tamás Sengel Dec 02 '18 at 11:04
  • Impossible to answer without knowing exactly what "As soon as I add a label (myLabel) to the cell in the xib and make an outlet for it in its custom class file" means. You would have to show us your xib details. But the implication of the error message is perfectly clear, and it means exactly what you say it does not, so read the duplicate again. – matt Dec 02 '18 at 20:53

1 Answers1

0

I ended up fixing this by deleting the swift file and xib file for the UICollectionViewCell and starting over. Not necessarily an answer to the problem but easier than wasting time trying to fix a file that was small to begin with. On the second try though when I made the class file I checked the box to automatically create the xib. This is better than making the two files separately as Xcode will put the collection view cell in the xib for you.