如何修复UICollectionViewCell的子类的不兼容指针 [英] How to fix an Incompatible pointer for subclass of UICollectionViewCell
问题描述
我已经实现了UICollectionViewCell
的子类UICollectionViewController
中创建单元格.现在,当我收集一个细胞时,为了对其进行处理,我会收到一条警告Incompatible pointer types initializing 'SPCell *' with an expression of type 'UICollectionViewCell *'
I've implemented a subclass SPCell
of UICollectionViewCell
which I am using to create cells in my UICollectionViewController
. Now, when I gather a cell, in order to do something with it, I get a warning Incompatible pointer types initializing 'SPCell *' with an expression of type 'UICollectionViewCell *'
这里是一个例子.我的自定义单元格包含一个图像,我想更改其Alpha值.但是在我分配单元格的那一行中,我得到了这个警告.
Here is an example. My custom cell holds an image, which I want to change the alpha value. But in the line, where I assign the cell, I get this warning.
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath;{
SPCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
cell.thumbnail.alpha=0.6;
}
谢谢.
推荐答案
您只需要添加强制类型转换,以使编译器知道您在做什么-
You just need to add a cast to let the compiler know what you are doing -
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath;{
SPCell *cell = (SPCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
cell.thumbnail.alpha=0.6;
}
这篇关于如何修复UICollectionViewCell的子类的不兼容指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!