[英]UICollectionView removing selected cells
I would like the delete the selected cels in the UICollectionView
. 我想删除UICollectionView
的选定UICollectionView
。
@property (weak, nonatomic) IBOutlet UICollectionView *cardTable;
@property (strong, nonatomic) NSMutableArray *cardTableArry; // of Card and datamodel
you can get the paths of them using as an array 您可以使用数组获取它们的路径
NSArray *indexPaths = [[self cardTable] indexPathsForSelectedItems];
you can't [[self cardTable] removeObjectsAtIndexes: indexPaths];
您不能[[self cardTable] removeObjectsAtIndexes: indexPaths];
as you need a NSIndexSet
. 因为您需要一个NSIndexSet
。
is there a way to convert the NSArray *indexPaths
to a NSIndexSet
ore do i need to do somting intierly difrend to get what i wand 有没有一种方法可以将NSArray *indexPaths
转换为NSIndexSet
矿石,我需要做无限遍地膨胀才能得到我想要的东西
I would like to convert the array in a NSIndexSet
我想在NSIndexSet
转换数组
[[self cardTableArry] deleteItemsAtIndexPaths: [[self cardTable] indexPathsForSelectedItems]];
The solution: 解决方案:
- (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.