【发布时间】:2013-12-13 12:20:03
【问题描述】:
我遇到了图像未显示的问题,即使它们正在加载。我已经尝试了几种不同的方法和相同的结果......没有图像。我确实得到了故事板中指定的大小和颜色的白色矩形。我在弹出窗口中得到了正确数量的矩形。日志正确显示名称和 ID。
如果我直接调用数组,我会得到相同的结果...白色矩形。
我的目标是iOS7。运行 Xcode 5.0.2。图像来自 SQL 数据库。这是一个实时应用程序,我正在将其更新到完整的 iOS7,并且我正在为 UICollectionView 换出自定义网格布局。使用 CollectionViewController,嵌入到 NavigationController 中,通过 UIButton 访问。如您所见,没有自定义单元格。这些图像将显示在弹出窗口中,然后用户可以选择以更改底层视图的背景。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BckgndCell" forIndexPath:indexPath];
NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row];
NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:@"id"];
int buttonTag = [buttonTagNumber intValue];
NSString *tempImage = [tempDict objectForKey:@"fileName"];
NSLog(@"Filename: %@", tempImage);
NSLog(@"ButtonTagNumber: %@", buttonTagNumber);
UIImageView *image = [[UIImageView alloc]init];
image.image = [UIImage imageNamed:tempImage];
NSLog(@"Image.image: %@", image.image);
// needed for selecting the background in didSelectItemAtIndexPath
_bgtag = buttonTag;
return cell;
}
修复包括在 cellForItemAtIndexPath 方法中实际命名 BackgroundCell (duh) 并在 BackgroundCell 控制器中创建一个小方法来设置图像。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
BackgroundCell *cell = (BackgroundCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"BckgndCell" forIndexPath:indexPath];
NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row];
NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:@"id"];
int buttonTag = [buttonTagNumber intValue];
NSString *tempImage = [tempDict objectForKey:@"fileName"];
[cell setImage:[UIImage imageNamed:tempImage]];
// needed for selecting the background in didSelectItemAtIndexPath
_bgtag = buttonTag;
return cell;
}
主单元格代码;
- (id)initWithFrame:(CGRect)frame
{
_backgroundImage = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
[self.contentView addSubview:_backgroundImage];
if (self) {
// Initialization code
}
return self;
}
-(void)setImage:(UIImage *)image
{
_backgroundImage.image = image;
}
【问题讨论】:
-
我现在有图片显示...为其他工作休息了很长时间。主要的事情,调用单元控制器和其他一些事情。我在上面添加了修复。
标签: ios7 uicollectionview popover