2017-01-09 74 views
1

我为超级UICollectionViewCell创建了自定义类。现在,当我打电话UICollectionView XCode自定义单元格

MyCollectionViewCell *itemView = [self.collectionView cellForItemAtIndexPath:indexPath]; 

我得到一个警告:

“指针类型不匹配”,(cellForItemAtIndexPath:indexPath]返回UICollectionView细胞)。

我该如何解决?

+3

什么是MyCollectionViewCell的基类?它应该是一个UICollectionViewCell。 – raidfive

+0

在上面调用哪个函数的方法? –

回答

3

警告是因为cellForItemAtIndexPath返回一个UICollecitonViewCell。您必须将其投射为MyCollectionViewCell,例如:

MyCollectionViewCell *itemView = (MyCollectionViewCell*)[self.collectionView cellForItemAtIndexPath:indexPath]; 

这应该照顾警告。

+0

非常真实。如果你使用自定义单元格,那么为了使它工作正常,投射很重要。 –

+0

谢谢。有效。 –

相关问题