我可以使用以下代码在UICollectionView
中加载图像,但问题是,它会在屏幕滚动后加载图像。如果没有Scroll,它将只显示空单元格
注意: - 我没有从任何链接(API)加载图像,它来自images.xcassets文件或支持文件。
以下是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
答案 0 :(得分:0)
致电
[collectionImageView reloadData]
at
- (void)viewWillAppear:(BOOL)animated