我想删除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]];
答案 0 :(得分:0)
解决方案:
- (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]];
}
}