Could not cast value of type 'UICollectionViewCell'

后端 未结 6 1107
野性不改
野性不改 2021-02-01 12:21

I use a custom CollectionViewCell in my Storyboard. When I start the app I get this message:

Could not cast value of type \'UICollectionViewCell\' to T

6条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 13:07

    You will get this error if you register your cell class both in Storyboard and in code. Choose one or the other, never both and the problem goes away.

    I wish Apple didn't include this bit of code in their templates:

    self.registerClass(SomeUICollectionCellClass.self, forCellWithReuseIdentifier: reuseIdentifier)
    

    Especially since they always recommend you register your cells through Storyboard. Makes things very confusing.

提交回复
热议问题