【发布时间】:2015-10-23 03:14:03
【问题描述】:
没有任何限制,我的 UICollectionViewCells 立即加载,完全没有任何问题。当我在情节提要中放置约束以使图像视图水平且垂直居中于单元格时,第一个图像单元格不会加载。我必须滚动几次,然后回到开头才能显示第一个图像单元格。解除约束,它会恢复正常工作。
我认为图像可能没有及时加载,但情况似乎并非如此。
我错过了什么?
我可以输入一些代码,但它是一个非常标准的 UICollectionView,在 ViewController 中有自定义单元格。
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = (CollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
NSString *imageName = [NSString stringWithFormat:@"%@", [self.urlArray objectAtIndex:indexPath.row]];
[cell setImageName:imageName];
[cell updateCell];
return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return self.collectionView.frame.size;
}
编辑: 我刚刚删除了导航栏,前 2 张图片正在导航栏后面加载。它们以默认原型 CollectionViewCell 的大小加载。一旦我滚动并返回它,它就是预期的大小。
【问题讨论】:
标签: ios objective-c iphone uicollectionview uicollectionviewcell