问题
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 *'
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;
}
Thanks in advance.
回答1:
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;
}
来源:https://stackoverflow.com/questions/23578412/how-to-fix-an-incompatible-pointer-for-subclass-of-uicollectionviewcell