[英]UICollectionView showing empty cells
我有一个显示图像数组的UICollectionView
。 单元格中的图像显示为白色框而不是真实图像。
我从另一个视图复制并粘贴了这个代码,它在另一个视图中效果很好......但不知何故,在另一个视图中,它显示所有图像,如白色框。
显示的框等于应显示的图像数。 所以信息正确传递。
图像显示为小白盒子,但是当我点击它们时,它们会将所选图像显示到我放置在其他位置的另一个UIImage
元素中(参见图像1,清除按钮左侧的绿色方块根据哪个白色单元格而变化触摸)。
谁能发现为什么Cell中的UIImage
无法正常显示?
也许值得一提的是我在同一视图中也有一个tableview
// in viewDidLoad method
[self.myCollection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cells"];
//
- (void)getAllIcons
{
NSArray* imgArrayRaw = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil];
NSMutableArray* imgArray = [[NSMutableArray alloc] init];
for (NSString* imgArrayProccesing in imgArrayRaw) {
NSString* ho = [imgArrayProccesing lastPathComponent];
if([ho rangeOfString:@"btn-"].location != NSNotFound){
[imgArray addObject:ho];
}
}
_imgFiles = [ NSMutableArray arrayWithObjects:imgArray,nil];
_imgFiles = _imgFiles[0];
_myCollection.hidden = NO;
[_myCollection reloadData];
}
// Collection View
#pragma mark - UICollectionView Datasource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [_imgFiles count];
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cells" forIndexPath:indexPath];
UIImageView *imageView = (UIImageView *)[cell viewWithTag:101];
imageView.image = [UIImage imageNamed:[_imgFiles objectAtIndex:indexPath.row]];
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self changeIconImage:[_imgFiles objectAtIndex:indexPath.row]];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(50, 50);
}
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(50, 20, 50, 20);
}
此搜索:
对不起,您没有提供足够的信息来完全诊断问题。 我怀疑你的代码有以下几种可能性;
a)在您的项目中找不到指定的图像,因此返回零;
b)找不到带有标签101的imageView,因此返回nil;
c)找到了imageView,但未启用或被隐藏。
我会在“cell.backgroundColor”行设置一个断点并检查每个返回值,并检查imageView的状态,看它是否已启用而不是隐藏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.