我收到此错误,尝试在
Swift中使用UICollectionView:
NSInternalInconsistencyException',reason: 'attempt to register a cell class which is not a subclass of UICollectionViewCell ((null))
但我想我正在注册这个单元格:
> ViewDidLoad:
override func viewDidLoad() { super.viewDidLoad() self.collectionView.registerClass(NSClassFromString("CollectionCell"),forCellWithReuseIdentifier:"CELL") }
> cellForItemAtIndexPath:
func collectionView(collectionView: UICollectionView,cellForItemAtIndexPath indexPath:NSIndexPath)->UICollectionViewCell { var cell = collectionView.dequeueReusableCellWithReuseIdentifier("CELL",forIndexPath: indexPath) as CollectionCell cell.titleLabel.text="cellText" return cell }
和细胞类:
class CollectionCell: UICollectionViewCell { @IBOutlet var titleLabel : UILabel init(coder aDecoder: NSCoder!) { super.init(coder: aDecoder) } }
任何帮助赞赏
解决方法
您需要将Swift样式的UICollectionViewCell子类传递给registerClass:
self.collectionView.registerClass(CollectionCell.self,forCellWithReuseIdentifier:"CELL")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。