Ios 目的C iVar亚类不';不使用相同的指针类型?

Ios 目的C iVar亚类不';不使用相同的指针类型?,ios,objective-c,pointers,nsindexpath,Ios,Objective C,Pointers,Nsindexpath,我犯了一个我不明白的错误。I子类UICollectionViewCell如下所示: - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath]; UICollectio

我犯了一个我不明白的错误。I子类UICollectionViewCell如下所示:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    CollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    UICollectionViewCell *cellOne = [collectionView cellForItemAtIndexPath:indexPath];
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的行的警告是“不兼容的指针类型使用类型为“UICollectionViewCell*”的表达式初始化“CollectionViewCell*”

如果它们都是同一个类,唯一的区别是iVar TXTLABLE,为什么它们的工作方式会不同

我正在尝试使用indexPath获取单元格。我假设这些单元格有一些存储空间,您可以使用传入的indexPath访问这些单元格

问题1。假设我可以使用传入的indexPath获取一个单元格,对吗

问题2。为什么一个叫工作,另一个不叫工作,因为他们都是同一个班级

CollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
方法
-cellForItemAtIndexPath:
定义为返回
UICollectionViewCell
。编译器不知道实际返回的是
CollectionViewCell

你必须沮丧地告诉编译器你知道你在做什么

CollectionViewCell *cell = (CollectionViewCell *) [collectionView cellForItemAtIndexPath:indexPath];
这将删除警告。不过这只是一个警告。它警告您可能出现错误,但代码将正常工作