How to get the name of the selected collection of collections?

This is a simple question that I thought would have an easy answer, but did not. I want to select a cell in the collection. The main problem is that I cannot attach a gesture recognizer to the prototype cell. I want to capture text from a label on a touching cell. I use this name in another function in my view.

Or a simpler question: is there a tutorial for selecting a tap from the list of items?

+5
source share
1 answer

You have a method collectionView:didSelectItemAtIndexPath:in the delegate. This should work when you collect the cell and give the correct indexPath for that particular cell.

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
    }
}
+6

All Articles