ios – 使用Swift的UICollectionView错误

ios – 使用Swift的UICollectionView错误,第1张

概述我收到此错误,尝试在 Swift中使用UICollectionView: NSInternalInconsistencyException', reason: 'attempt to register a cell class which is not a subclass of UICollectionViewCell ((null)) 但我想我正在注册这个单元格: > ViewDidLoad: 我收到此错误,尝试在 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")
总结

以上是内存溢出为你收集整理的ios – 使用Swift的UICollectionView错误全部内容,希望文章能够帮你解决ios – 使用Swift的UICollectionView错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1102295.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存