Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete cell from UICollectionView without reloading from top [closed]

Tags:

I am using a CollectionView in my ios app. Each collection cell contains a delete button. By clicking the button the cell should be deleted. After deletion, that space will be filled with below cell (I don't wish to reload the CollectionView and start from top again)

How do I delete a particular cell from UICollectionView with autolayout?

like image 884
New Jango Tester Avatar asked Apr 24 '13 10:04

New Jango Tester


People also ask

How do I remove cells from collectionView?

Build and Run the project and select the Edit Button. Select a few cells and press the Trash button to remove the items.

What is the difference between Uitableview and UICollectionView?

Tableiw is a simple list, which displays single-dimensional rows of data. It's smooth because of cell reuse and other magic. 2. UICollectionView is the model for displaying multidimensional data .

What is UICollectionView flow layout?

Overview. A flow layout is a type of collection view layout. Items in the collection view flow from one row or column (depending on the scrolling direction) to the next, with each row containing as many cells as will fit. Cells can be the same sizes or different sizes.


1 Answers

UICollectionView will animate and automatically rearrange the cells after deletion.

Delete selected items from collection view

[self.collectionView performBatchUpdates:^{      NSArray *selectedItemsIndexPaths = [self.collectionView indexPathsForSelectedItems];      // Delete the items from the data source.     [self deleteItemsFromDataSourceAtIndexPaths:selectedItemsIndexPaths];      // Now delete the items from the collection view.     [self.collectionView deleteItemsAtIndexPaths:selectedItemsIndexPaths];   } completion:nil];    // This method is for deleting the selected images from the data source array -(void)deleteItemsFromDataSourceAtIndexPaths:(NSArray  *)itemPaths {     NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];     for (NSIndexPath *itemPath  in itemPaths) {         [indexSet addIndex:itemPath.row];     }     [self.images removeObjectsAtIndexes:indexSet]; // self.images is my data source  } 
like image 81
Anil Varghese Avatar answered Sep 24 '22 08:09

Anil Varghese