ios - ImageView 未显示,但选择确实有效

标签 ios objective-c uicollectionview

我有一个 Collection View ,但没有显示图像,有趣的是 didSelectItemAtIndexPath 方法正在运行……可能是哪里出了问题?这是我的 cellForItemAtIndexPath 代码

cell *cell = [self.collectionPhotos dequeueReusableCellWithReuseIdentifier:@"CVCell" forIndexPath:indexPath];
NSString *nombre =[self.arrayPhotos objectAtIndex:indexPath.row];
//[cell.imageView setImage:[UIImage imageNamed:nombre]];

cell.imageView.image = [UIImage imageNamed:nombre];
return cell;

最佳答案

听起来您需要进行更深入的调试。

改变这一行:

cell.imageView.image = [UIImage imageNamed:nombre];

到:

if(cell)
{
    UIImage * imageForCell = [UIImage imageNamed: nombre];
    if(imageForCell)
    {
        if(cell.imageView)
            cell.imageView.image = imageForCell;
        else
            NSLog( @"surprise, imageView is null" );
    } else {
        NSLog( @"can't find image named %@", nombre );
    }
 } else {
     NSLog( @"cell is null" );
 }

看看会发生什么。

关于ios - ImageView 未显示,但选择确实有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19848159/

相关文章:

iphone - 基本的 CCArray 理解

ios - 如何以编程方式确定支持的应用程序方向?

ios - 是否真的有必要为 iOS 应用程序提供所有不同的应用程序图标大小?

ios - 更改部分页脚的背景颜色

ios - 更改部分标题标题的颜色

iphone - 在 UICollectionView 中检测滑动

iphone - 有没有办法在 iOS 中以编程方式打开和关闭蓝牙和/或 wifi?

ios - UITableViewController 内部 UINavigationController 和 UITabBarController 底部插入关闭

ios - Collection View performBatchUpdates 崩溃

ios - 如何在 willDisplay 单元格回调中访问 UICollectionView 中的特定单元格