不用block遍历NSMutableIndexSet

大家好,需要实现代码遍历 NSMutableIndexSet,我的代码如下:

if ([indexSet isNotNull] && [indexSet count] > 0){
        __weak  PNRHighlightViewController *weakSelf = self;
        [indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
            if ([[self.highlightedItems_ objectAtIndex:idx] isNotNull]){
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection: [weakSelf.collectionView numberOfSections]-1];
                [weakSelf.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
            }
        }];
    }

我想生成NSIndexPath数组,然后重新加载指定指针路径的collectionView,也就是block完成之后调用重新加载,不知道怎么实现?

遍历是同步执行的,所以在block期间遍历数组:

 if ([indexSet isNotNull] && [indexSet count] > 0){
        __weak  PNRHighlightViewController *weakSelf = self;

        NSMutableArray *indexPaths = [NSMutableArray new]; // Create your array

        [indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
            if ([[self.highlightedItems_ objectAtIndex:idx] isNotNull]){
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection: [weakSelf.collectionView numberOfSections]-1];
                [indexPaths addObject:indexPath];
            }
        }];
        [self.collectionView reloadItemsAtIndexPaths:indexPaths];
    }