_skyfish 2013-10-15 00:07 采纳率: 57.1%
浏览 6700

iOS: UICollectionViewcell里面的图片不能加载

跟实例基本差不多,但每次都显示image对象为nil,请问大神哪里有问题?

//

// ViewController.m
// PhotoViewer
//
// Created by yonzhang on 13-10-13.
// Copyright (c) 2013年 yonzhang. All rights reserved.
//

#import "ViewController.h"
#import "ImageCell.h"

@interface ViewController ()
@property NSMutableArray *photoArray;

@end

@implementation ViewController

  • (void)viewDidLoad
    {
    [super viewDidLoad];
    // self.collectionView
    self.collectionview.delegate = self;
    self.collectionview.dataSource = self;
    [self.collectionview registerClass: [ImageCell class] forCellWithReuseIdentifier:@"Cell"];
    // self.collectionview.dataSource = self;
    // Do any additional setup after loading the view, typically from a nib.
    }

  • (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

#pragma Collection View Data Souce

  • (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView
    {
    return 1;
    }

  • (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
    {
    return 1;
    }

-(UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
// UIImage *testImage = [UIImage imageNamed:@"4.JPG"];
cell.image.image = [UIImage imageNamed:@"4.JPG"];
return cell;
}

#pragma custommethod

@end

  • 写回答

2条回答 默认 最新

  • __block小凡 2015-01-13 06:45
    关注

    你的cell.image应该是UIImageView吧 如果是UIImageView的话,先把你的名称改了,image太特殊了,容易与系统命名重名,这句demo我感觉你应该用SDWebimage cell.image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"4.JPG"]];

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮