如何修复UICollectionViewCell的子类的不兼容指针

kch*_*mik 1 objective-c ios incomplete-type uicollectionviewcell

我已经实现了一个子类SPCellUICollectionViewCell,我用我创造我的细胞UICollectionViewController.现在,当我收集一个牢房时,为了对它做点什么,我得到一个警告Incompatible pointer types initializing 'SPCell *' with an expression of type 'UICollectionViewCell *'

这是一个例子.我的自定义单元格保存图像,我想更改alpha值.但是在我分配单元格的行中,我得到了这个警告.

- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath;{  
    SPCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
    cell.thumbnail.alpha=0.6;
}
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Pau*_*w11 6

你只需要添加一个强制转换程序让编译器知道你在做什么 -

- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath;{  
    SPCell *cell = (SPCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
    cell.thumbnail.alpha=0.6;
}
Run Code Online (Sandbox Code Playgroud)