gpt4 book ai didi

iphone - 无 block 地遍历 NSMutableIndexSet

转载 作者:行者123 更新时间:2023-11-28 20:25:01 26 4
gpt4 key购买 nike

目前我正在执行以下操作以迭代 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 完成后调用重新加载。我该怎么做?

最佳答案

一种方法是,

[indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
if ([[self.highlightedItems_ objectAtIndex:idx] isNotNull]){
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection: [weakSelf.collectionView numberOfSections]-1];
//store the indexPaths in an array or so
}
if (([indexSet count] - 1) == idx) { //or ([self.highlightedItems_ count] - 1)
//reload the collection view using the above array
}
}];
}

关于iphone - 无 block 地遍历 NSMutableIndexSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14365215/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com