我已经实现了 UICollectionViewCell
的子类 SPCell
,我用它在我的 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;
}
提前致谢。
最佳答案
你只需要添加一个强制转换让编译器知道你在做什么 -
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath;{
SPCell *cell = (SPCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
cell.thumbnail.alpha=0.6;
}
关于ios - 如何修复 UICollectionViewCell 子类的不兼容指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23578412/