0

collectionview新しいセルをスルーに挿入しても、セルは挿入されinsertitemsatindexpathsませんdeque。この関数が実行されるたびに新しいセルが作成されるため、メモリ使用量が増加します。このメソッドを使用して約 400 個のアイテムをループに挿入し、ループの反復ごとに 1 つのセルを挿入しています。つまり、これは反復ごとに 1 回呼び出されます。

新しいセルを作成しないようにするための解決策はありますか?

if ([singletonObj.photosSortOrder isEqualToString:@"DESC"]) {
                [self.MNCollectionView insertItemsAtIndexPaths:@[[NSIndexPath   indexPathForItem:0 inSection:0]]];
            }else{
                [self.MNCollectionView insertItemsAtIndexPaths:@[[NSIndexPath   indexPathForItem:[photos count]-1 inSection:0]]];
            }

これは 400 回呼び出され、呼び出されるたびに、デキューではなく新しいセルが挿入されます。他の誰かがこの現象を観察しましたか?

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

if ([cell.contentView.subviews count]>0) {
    [[cell.contentView.subviews objectAtIndex:0] removeFromSuperview];
}

// create the image views
UIImageView *MNPhotosImageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 78, 78)];
[MNPhotosImageView setImage:[self.collectionPhotos objectAtIndex:[indexPath row]]];
[MNPhotosImageView setContentMode:UIViewContentModeScaleAspectFill];
[MNPhotosImageView setClipsToBounds:YES];

[cell setBackgroundView:MNPhotosImageView];

if (cell.selected==YES && isInEditMode==YES) {


    UIImageView *checkMarkView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 78, 78)];
    [checkMarkView setContentMode:UIViewContentModeScaleAspectFit];
    [checkMarkView setImage:[UIImage imageNamed:@"checkMark.png"]];

    [cell.contentView addSubview:checkMarkView];

}
//else{
//    [[cell.contentView.subviews objectAtIndex:0] removeFromSuperview];
//}

MNPhotosImageView=nil;

return cell;
4

0 に答える 0