0

There is a label in UICollectionViewCell. I made 6 cells in UICollectionView and assigned a number (1-6) to a label in each cell. I call [UICollectionView reloadData] and expect same number in label. But, a label value is changed when cellForItemAtIndexPathas is called, like "1 3 1 3 1 3". It seems UICollectionViewCell is relocated in cellForItemAtIndexPathas.

Is there any way to keep it?

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    InfoCollectionViewCell *infoCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"InfoCell" forIndexPath:indexPath];

    [infoCell.cellText setText:[infoCell.cellText.text stringByAppendingString:[NSString stringWithFormat:@"%d\n",indexPath.row]]];

    return infoCell;
}
CaptJak
  • 3,592
  • 1
  • 29
  • 50
Won Young Lee
  • 165
  • 3
  • 14
  • The cells are usually 'made' within `cellForItemAtIndexPath`, typically by calling `dequeueReusableCellWithReuseIdentifier`, but I get the sense from the question that's not what you're doing. Without looking at the code, it is very difficult to get a sense for what might be going wrong there. I would suggest adding some sample code to your question - would make it a lot easier to answer. – Timothy Johns Feb 08 '15 at 14:21
  • My code is attached. I expect infoCell.cellText label is same whenever this is called. However, This is changed in random. – Won Young Lee Feb 08 '15 at 14:58

1 Answers1

0

You have a reuse issue with the label that you added to your cell.

I made a post about how to subclass UICollectionViewCell properly. You can check it here : UICollectionView adding image to a cell

Community
  • 1
  • 1
Kujey
  • 1,122
  • 6
  • 17