UICollectionViewCell加载问题?

在UIViewController里定义了一个UICollectionView,注册cell

UIViewController.h里面

@property (weak, nonatomic) IBOutlet UICollectionView *pictureCollection;

UIViewController.m里面

[self.pictureCollection registerClass:[CAPictureCell class] forCellWithReuseIdentifier:@"capicture"];

加载cell的代码

-(UICollectionViewCell )collectionView:(UICollectionView )collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{


CAPictureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"capicture" forIndexPath:indexPath];
if (cell==nil) {
    cell=[[CAPictureCell alloc]init];
}
NSDictionary *dic = [[NSDictionary alloc] init];
[cell setInfo:dic];
return cell;

}

CAPictureCell.m文件里面

  • (void)setInfo:(NSDictionary*)d{

    self.backgroundColor = [UIColor redColor];
    [self.CAPicture setImage:[UIImage imageNamed:@"logoGrey.png"]];
    self.CALabel.text = @"222";

    }

想要实现cell
图片描述

目前只有backgroundColor出来了

图片描述

求助。

阅读 5k
2 个回答

加断点,看setInfo有么有走到

新手上路,请多包涵

如果你是用 nib/storyboard 做的 cell,不要用:

[self.pictureCollection registerClass:[CAPictureCell class] forCellWithReuseIdentifier:@"capicture"];

而是:

UINib *cellNib = [UINib nibWithNibName:<#Your Nib File#> bundle:nil];
[self.tableView registerNib:cellNib forCellReuseIdentifier:@"capicture"];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题