Ios UICollectionView重新加载数据异常行为

Ios UICollectionView重新加载数据异常行为,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我有故事板,UICollectionView视图,带插座的视图控制器。使用web服务加载记录: [[API sharedInstance] getCommentsForArticle:[self.article[@"id"] integerValue] withPage:self.commentsPage onSuccess:^(NSArray *responseData) { NSLog(@"LoadCommentsThread: %@", [NSThread currentThrea

我有故事板,UICollectionView视图,带插座的视图控制器。使用web服务加载记录:

[[API sharedInstance] getCommentsForArticle:[self.article[@"id"] integerValue] withPage:self.commentsPage onSuccess:^(NSArray *responseData) {
    NSLog(@"LoadCommentsThread: %@", [NSThread currentThread]);
    [self.allCommentsCache addObjectsFromArray:responseData];
    [self.allCommentsCollectionView reloadData];
} onFail:^(NSError *error) {
    DLog(@"Handle error");
}];
每个collectionview请求的项目数正确:

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
项目的大小计算正确,即使每个单元格的大小不变:

if (collectionView == self.allCommentsCollectionView) {
    NSString *commentText = self.allCommentsCache[indexPath.row][@"text"];
    CGSize maximumLabelSize = CGSizeMake(300,9999);
    CGSize expectedLabelSize = [commentText sizeWithFont:[UIFont fontWithName:@"HelveticaNeue" size:15.0f]
                                       constrainedToSize:maximumLabelSize
                                           lineBreakMode:NSLineBreakByWordWrapping];
    return CGSizeMake(320, 150);
}
问题在于:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
在初始运行时,数据源阵列上有30个元素,并且已正确加载。当有更多加载项时,numberofitems返回正确的项数,sizeforitem将遍历所有项,但cellforitem仅用于最初的30项。不管有100、200或更多物品


有人有类似问题吗?

这听起来像是正常行为,只加载当前可见的单元格。开始滚动时应加载剩余单元格。好的,通过更新collectionview frame;)解决此问题@blackrain:当你找到解决方案时,请在这里添加。所以它可以帮助别人。