我收到一个错误,我不明白。我继承UICollectionViewCell如下:Objective C子类iVar不采用相同的指针类型?
CollectionViewCell.h
@interface CollectionViewCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UILabel *txtLabel;
在一个视图控制器,我用它如下:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
UICollectionViewCell *cellOne = [collectionView cellForItemAtIndexPath:indexPath];
使用CollectionViewCell第一个呼叫发出警告,第二届一个不,他们都是同一班。当它被选中时更改单元格并访问它中的数据。
警告与CollectionViewCell的行是“不兼容的指针类型初始化‘CollectionViewCell *’与类型的表达式‘UICollectionViewCell *’”
如果它们都相同的类,唯一的区别是IVAR txtLabel,他们为什么会以不同的方式工作?
我想获得使用indexPath的单元格。我假设有一些存储这些单元格,您可以使用传入的indexPath访问这些单元格。
Q1。我正确地假设我可以通过使用传入的indexPath来获取单元格吗? Q2302。为什么一个电话会工作而另一个不是同一个班级?