UICollectionView删除选定的单元格

时间:2014-04-10 13:21:42

标签: ios iphone objective-c 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]]; 

1 个答案:

答案 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]];
    }
}