繁体   English   中英

UICollectionView删除选定的单元格

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM