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 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?