gpt4 book ai didi

ios - UICollectionView visibleCells 在滚动前返回 0

转载 作者:可可西里 更新时间:2023-11-01 03:36:14 26 4
gpt4 key购买 nike

我有一个实现延迟加载的 UICollectionView,

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
[self loadImagesToVisiableCells];
}

效果不错。然而,问题是在任何滚动之前,前几个单元格显示占位符图像。因此,我尝试在检索要在下面的 UICollectionView 中显示的 json 文件的回调中调用 loadImagesToVisiableCells,

- (void)handleReceivedData: (NSArray*)results returnArrayOrDic:(NSNumber *)returnArrayOrDic{
NSLog(@"***************************");
NSLog(@"handleReceivedData has been called from PromotionViewController");
NSLog(@"jsonArray Length:%d",[results count]);
NSLog(@"jreturnArrayOrDic:%@",returnArrayOrDic);
if([returnArrayOrDic boolValue] == YES){
for(NSDictionary *dealDic in results) {
NSLog(@"dealDic: %@", dealDic);
//to populate the dealArray
Deal *deal = [[Deal alloc] initWithDict:dealDic];
[dealArray addObject:deal];
}
NSLog(@"%d deals have been populated to dealArray",[dealArray count]);
}else{
NSDictionary *jsonDictionary = (NSDictionary *)results;
for(id key in jsonDictionary) {

id value = [jsonDictionary objectForKey:key];

NSString *keyAsString = (NSString *)key;
NSString *valueAsString = (NSString *)value;

NSLog(@"key: %@", keyAsString);
NSLog(@"value: %@", valueAsString);
}
}
[self.collectionView reloadData];
[self loadImagesToVisiableCells];
}

调试消息显示在任何滚动之前,[[collectionView visibleCells] count] 返回 0。

    - (void)loadImagesToVisiableCells{
NSLog(@"starting loadImagesToVisiableCells, visibleCells:%d",[[collectionView visibleCells] count]);
....
}

有什么想法吗?

问候锤子

最佳答案

感谢Reloading a UICollectionView using reloadData method returns immediately before reloading data

该问题是由于重载未完成引起的。解决方案是,

[collectionView reloadData];
**[self.collectionView layoutIfNeeded];**
[self loadImagesToVisiableCells];

关于ios - UICollectionView visibleCells 在滚动前返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26055626/

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