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

标签 ios objective-c uicollectionviewcell incomplete-type

我已经实现了 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/

相关文章:

ios - 加入UICollectionViewCell像HTML的rowpan表一样吗?

ios - 关于APNS使用的问题

ios - 使用 indexPath.row 从 tableView 中的 Dictionary 获取值?

objective-c - 从 GDB 获取值后如何编辑二进制文件

iphone - 访问/设置iOS设置应用的全局设置

ios - 如何快速将静态单元格拖入 tableView?

iphone - 将 UINavigationBar 移出屏幕但下方区域不可触摸

ios - AudioKit:噪声门

ios - 如何从Apple Push Notifications获取userInfo

ios - 如何防止在 cellForItemAt 中重新加载 UICollectionViewCells?