[英]Deleting selected cells in uicollectionview
我在uicollectionviewcell中放置了一個按鈕,當按下該按鈕時,它以編程方式將單元格設置為選中狀態。
- (void) deleteItem:(id)sender
{
self.selected = YES;
[self.cellOptionsDelegate deleteItem];
}
然后它委托給uicollectionviewcontroller刪除所選的項目。
- (void) deleteItem
{
NSArray* selectedItemsIndexPaths = [self.collectionView indexPathsForSelectedItems];
// Delete the items from the data source.
[self.taskArray removeObjectAtIndex:[[selectedItemsIndexPaths objectAtIndex:0] row]];
// Now delete the items from the collection view.
[self.collectionView deleteItemsAtIndexPaths:selectedItemsIndexPaths];
}
但是,當我使用uicollectionview方法indexPathsForSelectedItems獲取所選項時,它沒有看到我已選擇該項並且列表為空。 我正在使用印刷機為另一種功能選擇委托方法,所以我希望按照我上面解釋的內容做一些事情。 有沒有辦法讓這項工作或更好的方式通知控制器按下單元格中的按鈕綁定到特定索引路徑上的單元格?
謝謝。
只需從單元格的deleteItem方法發送一個單元格指針
- (void) deleteItem:(id)sender
{
self.selected = YES;
[self.cellOptionsDelegate deleteItem:self];
}
並將uicollectionviewcontroller的方法更改為
- (void) deleteItem:(UICollectionViewCell*)cellToDelete
{
NSIndexPath indexPathToDelete = [self indexPathForCell: cellToDelete];
// Delete the items from the data source.
[self.taskArray removeObjectAtIndex:[indexPathToDelete row]];
// Now delete the items from the collection view.
[self.collectionView deleteItemsAtIndexPaths:@[indexPathToDelete]];
}
不要忘記在* .h文件中更新'(void)deleteItem:(UICollectionViewCell *)cellToDelete'聲明。
通過委托方法發送單元格並使用以下方法解決:
NSIndexPath* indexPath = [self.collectionView indexPathForCell:cell];
動畫:
[self.collectionView performBatchUpdates:^ {
[_array removeObject:file];
[self.collectionView deleteItemsAtIndexPaths:@[indexPath]];
} completion:nil];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.