无法转换类型“UICollectionViewCell"的值 [英] Could not cast value of type 'UICollectionViewCell'

查看:24
本文介绍了无法转换类型“UICollectionViewCell"的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Storyboard 中使用了自定义 CollectionViewCell.当我启动应用程序时,我收到以下消息:

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

无法将UICollectionViewCell"类型的值转换为TestProject.CollectionViewCell.

Could not cast value of type 'UICollectionViewCell' to TestProject.CollectionViewCell.

推荐答案

Xcode 中 CollectionViewController 的模板在 viewDidLoad 中附带了这行代码,它改变了故事板中的规范.

The template for a CollectionViewController in Xcode comes with this line of code in viewDidLoad, which changes the specification in your storyboard.

// Register cell classes
self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

只需删除该行.

在较旧的 Swift 版本中,该行是:

In older Swift versions the line is:

// Register cell classes
self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

这篇关于无法转换类型“UICollectionViewCell"的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆