How to keep the didSelect action in UICollectionView in Objective-c?
<p>I have a UICollectionView and I add from my cellForItemAtIndexPath 12 cells. When I do scroll on this to see down cells, all functions is preserved, but when I do scroll to go up again, some cells don't execute the function loaded in didSelectItemAtIndexPath. </p>

<p><strong>I set disabled some rows. But not the row that I clicked</strong> Why could be this? Could be a bad prepare for reuse cell?</p>

<p>I'm trying the reuse function, but this only affect drawing the cell wrong or on the another position and the function added in didSelectItemAtIndexPath not work:</p>

<pre><code>[self.myCollectionView reloadData];

[self.myCollectionView layoutIfNeeded];

NSArray *visibleItems = [self.myCollectionView indexPathsForVisibleItems];
    NSIndexPath *currentItem = [visibleItems objectAtIndex:0];
    NSIndexPath *nextItem = [NSIndexPath indexPathForItem:currentItem.item + 1 inSection:currentItem.section];
    [self.myCollectionView scrollToItemAtIndexPath:nextItem atScrollPosition:UICollectionViewScrollPositionTop animated:YES];
</code></pre>

<p>WHen I do scroll and the do click to one cell, this not open my secondViewController, I think that this cell is gettin a wrong index that was disabled.</p>

<pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
 {

MyViewController *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];

switch ([indexPath row]) {
    case 0:
        titleCell= @"Title0";
        detailCell=@"Detail0";
        if([indexPath row]==2){
             [cell setUserInteractionEnabled:NO];//Here I set disable Could be the problem caused by this??
        }

        [cell.image setHidden:YES];
        cell.image.contentMode = UIViewContentModeScaleAspectFit;
        break;
    //Here other cases with the same structure

    return cell;
  }

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
 {
      [collectionView deselectItemAtIndexPath:indexPath animated:NO];
 MySecondClass *secondClass = [self.storyboard instantiateViewControllerWithIdentifier:@"myVC"];
 [self.navigationController pushViewController:secondClass animated:YES];
 }

 -(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
 //Here assign yellow background color to first row and white color to the second row
 }
</code></pre>

<p>And in my cell class I added the prepareForReuse but this not work...</p>

<pre><code>- (void)prepareForReuse {
    [super prepareForReuse];

    [self removeFromSuperview];
    [self setNeedsLayout];
}
</code></pre>