Swift CollectionReusableView注册失败原因

1.程序奔溃并且报错 reason: 'could not dequeue a view of kind: UICollectionElementKindSectionHeader with identifier GTNotificationReusableView - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' 时,应该查看是否已经注册以及注册方法有没有出错,collectionView.register(UINib(nibName:headerlName, bundle:nil), forSupplementaryViewOfKind:UICollectionElementKindSectionHeader, withReuseIdentifier:headerlName)

2.程序奔溃并且报错 Could not cast value of type 'UICollectionReusableView' (0x1137cafe0) to xxx 

这个是因为类型不同强转导致的,这种情况修改的方法是将CollectionReusableView的类型改成我们自定义的类名。

修改前
修改后
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容