user862972
user862972

Reputation: 224

UICollectionView cellForItemAtIndexPath returns nil after scrolling

I have an issue with UICollectionView. The below code is to return get the cell at a point (CGPoint)

CollectionViewCell* cell = (CollectionViewCell*) [mCollectionView cellForItemAtIndexPath:       [mCollectionView indexPathForItemAtPoint:point]];
if (cell)
     NSLog(@"Cell exists");
else
     NSLog(@"Cell doesn't exist");

This returns a valid cell if the UICollectionView is left still. If it is scrolled downwards, it returns nil. I am not sure what's the issue. UICollectionView scrolling works fine. No issues with the collectionview cells.

Could some one help me out here, please?

Upvotes: 3

Views: 4312

Answers (2)

J. Lopes
J. Lopes

Reputation: 1345

If someone else has this problem. If you have been using:

[myCollectionView registerClass:[customCell class] forCellWithReuseIdentifier:yourCellIdentifier];

inside of viewDidAppear and you have been using prototype to create cell on storyboard or using a nib file, you should remove [registerClass:forCellWithReuseIdentifier:]

Also, if you're looking for a good explanation on what registerCell does and how to use it check out this link

Upvotes: 0

Javi Campaña
Javi Campaña

Reputation: 1481

Is not a issue, in UICollectionView and UITableView, the cells that no are visibles are removed from memory.

Upvotes: 1

Related Questions