UICollectionViewCell加载问题?

发布于 2022-09-02 16:07:07 字数 1295 浏览 19 评论 0

在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出来了

图片描述

求助。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掩饰不了的爱 2022-09-09 16:07:07

加断点,看setInfo有么有走到

月竹挽风 2022-09-09 16:07:07

如果你是用 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"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文