[英]UICollectionView removing selected cells
我想刪除UICollectionView
的選定UICollectionView
。
@property (weak, nonatomic) IBOutlet UICollectionView *cardTable;
@property (strong, nonatomic) NSMutableArray *cardTableArry; // of Card and datamodel
您可以使用數組獲取它們的路徑
NSArray *indexPaths = [[self cardTable] indexPathsForSelectedItems];
您不能[[self cardTable] removeObjectsAtIndexes: indexPaths];
因為您需要一個NSIndexSet
。
有沒有一種方法可以將NSArray *indexPaths
轉換為NSIndexSet
礦石,我需要做無限遍地膨脹才能得到我想要的東西
我想在NSIndexSet
轉換數組
[[self cardTableArry] deleteItemsAtIndexPaths: [[self cardTable] indexPathsForSelectedItems]];
解決方案:
- (void) removeCardsFromTable: (NSArray *) indexPaths {
NSMutableArray *cards = [[NSMutableArray alloc] init];
for (NSInteger selectedLoop = 0; selectedLoop < 3; selectedLoop++) {
NSIndexPath *card = [indexPaths objectAtIndex: selectedLoop];
[cards addObject: [[self cardTable] objectAtIndex: [card item]]];
}
for (NSInteger selectedLoop = 0; selectedLoop < 3; selectedLoop++) {
[[self cardTable] removeObject: [cards objectAtIndex: selectedLoop]];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.