Sanket
Sanket

Reputation: 31

How to load images in UICollectionView "without Scroll"?

I am able to load Images in UICollectionView, using following code, but the problem is, It will load images after the screen is Scrolled. Without Scroll it will just display only Empty Cells.

Note:- I am not loading images from any link(API), It is from images.xcassets file or supporting Files.

Here is code for 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


Following Image, When I run program but without scrolling.If I scroll, it will load image one-by one.
enter image description here

Upvotes: 0

Views: 574

Answers (1)

Henson Fang
Henson Fang

Reputation: 1207

call

[collectionImageView reloadData]

at

- (void)viewWillAppear:(BOOL)animated

Upvotes: 0

Related Questions