我从一个很长的时间进行恢复,这是以前的工作应用程序,所以我假设它的下跌在新版本的iOS操作系统的变化。图像UICollectionView不显示从NSMutableArray的
当我在模拟器上运行应用程序时,没有显示图像,但正在创建单元并显示名称。我知道我必须在某处失去一些东西,但不能在我的生活中看到它,但是我不熟悉最近的变化。
任何帮助深表感谢,这是我的代码:
- (void)createData {
self.graniteImages = [NSMutableArray array];
[self.graniteImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Angel Cream", @"name",
@"angel-cream.jpg", @"image", nil]];
[self.graniteImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Angola Black", @"name" ,
@"angola_black1.jpg", @"image" , nil]];
[self.graniteImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Angola Silver", @"name" ,
@"angola-silver1.jpg", @"image" , nil]];
[self.collectionView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.graniteImages.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *graniteImageView = (UIImageView *)[cell viewWithTag:100];
graniteImageView.image = [UIImage imageNamed:[[self.graniteImages objectAtIndex:indexPath.row] objectForKey:@"image"]];
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (_startingIndexPath) {
NSInteger currentIndex = floor((scrollView.contentOffset.x - scrollView.bounds.size.width/1)/scrollView.bounds.size.width) + 1;
if (currentIndex < [self.graniteImages count]) {
self.title = self.graniteImages[currentIndex][@"name"];
}
}
}
你可以试试,看看imageNamed返回的实际图像,也许有事与资产,就可以加载名称那些图像,别的地方? – JackRobinson
看起来有可能您使用的文件名不是资产名称。 – torinpitchers
您的图片在资产文件中?然后尝试删除'.jpg'扩展名。 @JackRobinson可能是对的,你的图片可能不会被加载。 – vitormm