我已经实现了一个 UICollectionView
图片库。每个 cell
都有一些 View ,我想在更改当前 cell
时隐藏或显示这些 View ,至少在事件开始时。有什么方法吗?还是我应该委托(delegate)他人做某事?我有 启用分页
和自定义 cell
和 FlowLayout
。
我所做的一切几乎都是这样tutorial
最佳答案
一种方法是将当前选定的单元格索引保留在 viewController 的局部变量中,并在选择另一个单元格时使用该索引执行任何操作:
@property (nonatomic) NSIndexPath *selectedCellIndexPath;
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if (![self.selectedCellIndexPath isEqual:indexPath]) {
UICollectionViewCell *lastSelectedCell = [collectionView cellForItemAtIndexPath:selectedIndexPath];
// Perform any change to lastSelectedCell before deselecting it
[collectionView deselectItemAtIndexPath:lastSelectedIndexPath animated:YES];
}
self.selectedCellIndexPath = indexPath;
UICollectionViewCell *selectedCell = [collectionView cellForItemAtIndexPath:indexPath];
// Change what you want in the newly selected cell;
}
关于ios - 我应该使用哪种方法在 UICollectionViewCell 之间执行某些操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20553124/