oOOMIAO 2013-01-17 06:08 采纳率: 10%
浏览 4274

不用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完成之后调用重新加载,不知道怎么实现?

  • 写回答

1条回答

  • g989_1314125 2013-01-17 06:39
    关注

    遍历是同步执行的,所以在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];
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记