Pergunta

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.

Foi útil?

Solução

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;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top