簡體   English   中英

UICollectionview中的單元格在刪除索引處的圖像時不會刪除

[英]Cells in UICollectionview not removing on deleting image at index

我創建了一個UICollectionView ,其中設置了單元格的背景圖像。

UIImage *image = imageArray[indexPath.row];
cell.backgroundView = [[UIImageView alloc] initWithImage:image];

問題是,如果我從用於創建UICollectionView的數組中刪除圖像並重新加載collectionView ,則將刪除該單元格,但仍顯示該圖像。

這是我的刪除和刷新代碼:

[collectionImages performBatchUpdates:^{
    [imageArray removeObjectAtIndex:indexPath.row];
    NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:indexPath.row
                                                 inSection:0];
    [collectionImages deleteItemsAtIndexPaths:[NSArray arrayWithObject:
                                               indexPath1]];
} completion:^(BOOL finished) {
}];

[collectionImages setNeedsDisplay];

主要問題是圖像已從數組中甚至從UICollectionView刪除,但沒有從視圖中刪除。 好像它是顯示在緩存中的某個位置。

試試[collectionImages reloadData]; 而不是[collectionImages setNeedsDisplay];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM