【问题标题】:How do I get the name of a selected collectionviewcell?如何获取所选 collectionviewcell 的名称?
【发布时间】:2013-01-17 13:48:30
【问题描述】:

这是一个简单的问题,我认为答案很容易找到,但没有。我想在集合视图中选择一个单元格。主要问题是我无法将手势识别器附加到原型单元。我想从被触摸的单元格上的标签中获取文本。在我看来,我在不同的函数中使用了这个名称。

或者一个更简单的问题:是否有关于从项目列表中点击选择的教程?

【问题讨论】:

    标签: ios objective-c selection gesture-recognition uicollectionviewcell


    【解决方案1】:

    您在委托中有collectionView:didSelectItemAtIndexPath: 方法。当您收集单元格并为您提供该特定单元格的正确 indexPath 时,这应该会触发。

    将此 indexPath 与 collectionView 的 cellForItemAtIndexPath: 结合使用以访问特定单元格。

    例子:

    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
        [self manipulateCellAtIndexPath:indexPath];
    }
    
    -(void) manipulateCellAtIndexPath:(NSIndexPath*)indexPath {
        UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
        // Now do what you want...
    }
    

    而且,只要我在这里。 Swift 版本:

    override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
        manipulateCellAtIndexPath(indexPath)
    }
    
    func manipulateCellAtIndexPath(indexPath: NSIndexPath) {
        if let cell = collectionView?.cellForItemAtIndexPath(indexPath) {
            // manipulate cell
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-30
      • 2011-09-24
      • 2021-07-16
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多