简体   繁体   中英

UICollectionView reuse cell issue

I have a problem with collection view cell. When my collection view first loaded, it display items like that:

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{


    CalendarCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"CalendarCell" forIndexPath:indexPath];

    [cell bindDate:_datesMgr.currentMonthItems[indexPath.row] andNowDate:_datesMgr.nowDate];


    // bind events

    if (_eventsMgr.eventsArray.count > 0){

        for (int i = 0; i < _eventsMgr.eventsArray.count ; i ++) {
            [cell bindConference:_eventsMgr.eventsArray[i]];
        }
    }


    return cell;
}

Inside those methods are logic for adding subviews to custom cell class, which depend on certain circumstances.

Its all work, but, when collection view reloaded (i did force reload after 1 second) some of cells are reused and placed on others, therefore, it show "old" images and subviews.

I could see possible solution in forcing uicollection view to stop reusing cells (it is, load new cells every time). Is there any way to do this?

Try to implement prepareForReuse method for reset your old content in your custom UICollectionViewCell

-(void)prepareForReuse {
   [super prepareForReuse];
   self.yourimageview.image = nil; //and etc.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM