我已经实施了UICollectionView
图片库。每个cell
都有一些视图,我想在我更改当前cell
时隐藏或显示该视图,至少在事件开始时。有什么方法吗?或者我应该由代表做什么?我有paging enabled
和自定义cell
以及FlowLayout
。
我已经做了几乎所有事情tutorial
答案 0 :(得分:1)
一种方法是将当前选定的单元格索引保留在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;
}