0

I am facing some problem with UICollectionView. I am storing the original cell in instance variable. check below code.

originalCell = (CollectionViewCell *)[_colloctionView cellForItemAtIndexPath:dragIndexPath];
   NSLog(@"Main Cell %@",originalCell);

Console O/P

  Main Cell <CollectionViewCell: 0xdae4fc0; baseClass =
 UICollectionViewCell; frame = (216.5 30; 95 113); clipsToBounds = YES;
 alpha = 0.3; opaque = NO; tag = 3; layer = <CALayer: 0xdae5070>>

Now I am scrolling then i check the cell object. it gives me like that.

Console O/P

  ENd <CollectionViewCell: 0xdae4fc0; baseClass = UICollectionViewCell;
 frame = (112.5 548.5; 95 113); clipsToBounds = YES; opaque = NO; tag =
 8; layer = <CALayer: 0xdae5070>>

As you can see object value is changed now. i think this is the problem of reauseablity.

But How can i solve this problem in easy way. Thanks

Sunny Shah
  • 12,990
  • 9
  • 50
  • 86

1 Answers1

0

Yes it is cell reusability issue, try creating cell identifier like this. It will work.

NSString *identifier =[NSString stringWithFormat:@"%d_%d",indexPath.row,indexPath.section];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }

If you are using custom cell, cell creation code will be changed accordingly.

Shahab Qureshi
  • 952
  • 1
  • 7
  • 19