Ios “如何在UICollectionView中加载图像”;没有卷轴;?

Ios “如何在UICollectionView中加载图像”;没有卷轴;?,ios,objective-c,uicollectionview,lazy-loading,uicollectionviewcell,Ios,Objective C,Uicollectionview,Lazy Loading,Uicollectionviewcell,我可以使用以下代码在UICollectionView中加载图像,但问题是,它会在屏幕滚动后加载图像。如果不滚动,则只显示空单元格。 注意:-我不是从任何链接(API)加载图像,而是从images.xcsets文件或支持文件加载图像 以下是UICollectionView的代码: #import "ViewController.h" @interface ViewController() @end @implementation ViewController -(void)viewDidLoad

我可以使用以下代码在
UICollectionView
中加载图像,但问题是,它会在屏幕滚动后加载图像。如果不滚动,则只显示空单元格。

注意:-我不是从任何链接(API)加载图像,而是从images.xcsets文件或支持文件加载图像

以下是
UICollectionView
的代码:

#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
-(void)viewDidLoad {
[super viewDidLoad];
collectionImages = [NSArray arrayWithObjects:@"car1.jpeg",@"car2.jpeg",@"car3.jpeg",@"car4.jpeg",@"car5.jpeg",@"car6.jpeg", nil];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return collectionImages.count;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier =@"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

UIImageView * collectionImageView = (UIImageView *) [cell viewWithTag:100];

    collectionImageView.image = [UIImage imageNamed:[collectionImages objectAtIndex:indexPath.item]];
return cell;
}

@end

下图,当我运行程序但不滚动时。如果我滚动,它将逐个加载图像。
打电话

[collectionImageView reloadData]


请尝试
cell.collectionImageView.image
@Sanket是否使用UICollectionViewCell类?默认情况下,集合视图仅为可见对象加载图像cells@aaisataev,“cell.collectionImageView.image”出现错误。你能详细解释一下吗?它将以无限循环的方式运行。你能解释一下如何做到这一点以及它将如何工作吗?
- (void)viewWillAppear:(BOOL)animated