ios - 我应该使用哪种方法在 UICollectionViewCell 之间执行某些操作?

标签 ios objective-c uicollectionview uicollectionviewcell

我已经实现了一个 UICollectionView 图片库。每个 cell 都有一些 View ,我想在更改当前 cell 时隐藏或显示这些 View ,至少在事件开始时。有什么方法吗?还是我应该委托(delegate)他人做某事?我有 启用分页 和自定义 cellFlowLayout

我所做的一切几乎都是这样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/

相关文章:

ios - SpriteKit,Swift 2.0 - 反向 ScrollView

ios - UIWebView 和顶栏 iPhone 5 iPhone 4 缩放问题

objective-c - 如果属性被定义为副本,那么在分配给 ivar 时是否还需要进行副本?

ios - 从 Collection View 传递到 View Controller 的简单图像数据失败

ios - 在 xcode 4.3 上运行测试

ios - UIVisualEffectView 未设置为零

ios-获取唯一标识符,重新安装应用程序后该标识符必须相同

ios - 我如何使用 NSJSONSerialization 与特殊字符,如 "ñ"?

ios - 通过 UICollectionView 单元格快速枚举 - Swift

ios - 如何获取相对于内容大小和设备宽度的 x 位置?