Retrieve custom cells in didSelectItemAtIndexPath

Asked 2 years ago, Updated 2 years ago, 111 views

When I tap Cell in CollectionView, I am trying to implement the process such as adding subView to Cell like the camera roll in the Twitter app.
That's why I wrote this.

-(CameraRollCell*)collectionView:(UICollectionView*)collectionViewcellForItemAtIndexPath:(NSIndexPath*)indexPath{
    CameraRollCell* cell= [collectionView requestReusableCellWithReuseIdentifier: cellID forIndexPath:indexPath];
    return cell;
}

- (void) collectionView: (UICollectionView*) collectionView didSelectItemAtIndexPath: (NSIndexPath*)indexPath{
    CameraRollCell*cell= [collectionView cellForItemAtIndexPath:indexPath];
    cell selectPhoto;
}

US>Preparing a custom class inherited from the UICollectionViewCell` and retrieving the cell when tapped.After retrieval, you are invoking a method to add the subView that the custom cell has.

However, cellForItemAtIndexPath: will probably not be able to retrieve custom class Cells, so it will play...

So I have a question.

I look forward to hearing from you.

Supplemental
- I do not use StoryBoard.Code-only implementation.

ios objective-c uicollectionview uicollectionviewcell

2022-09-30 21:13

1 Answers

in viewDidLoad[self.collectionViewregisterClass:[CameraRollCell class] Added forCellWithReuseIdentifier:cameraRollCellID; and it worked fine.
Thank you for your comment.


2022-09-30 21:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.