我收到此错误,尝试在
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")