• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 如何在 Storyboard 中使用自定义 UICollectionViewCell?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 18:27:20 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我不明白为什么自定义单元格在 Storyboard 中无法识别。

TNTopStoriesCollectionViewController:

static NSString * const reuseIdentifier = @"TNTopNewsCellItem";

- (UICollectionViewCell *)collectionViewUICollectionView *)collectionView cellForItemAtIndexPathNSIndexPath *)indexPath
{
    TNTopStoriesCollectionViewCell *cell = (TNTopStoriesCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    // Configure the cell
    [self preLoadImagesForCategory:_dataStore.fiveTopStories[indexPath.item] andImageView:cell.itemImage];
    return cell;
}

我正在为 collectionView 使用 Storyboard : enter image description here

并且单元格也正确指向自定义类: enter image description here

#import <UIKit/UIKit.h>

@interface TNTopStoriesCollectionViewCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *itemImage;
@property (weak, nonatomic) IBOutlet UILabel *title;

@end

并且还使用了正确的单元格标识符: enter image description here

但我在 cellForItemAtIndexPath 方法中得到了这个异常:

[UICollectionViewCell itemImage]: unrecognized selector sent to instance

但是为什么?

更新:

我按照建议做了所有事情,现在得到了这个: enter image description here

但是它仍然在同一个地方失败。



Best Answer-推荐答案


在场景中对象的分层名称列表中,该单元在左侧被称为“ Collection View 单元”,并且没有更改为“热门故事 Collection View 单元”这一事实表明您没有实际上已成功将 Storyboard中的类更改为 TNTopStoriesCollectionViewCell。

(请注意 Collection View Controller 如何在左侧列为热门故事 Collection View Controller 。同样的事情应该发生在单元格上。)

你在左边看到的应该更像这样:

enter image description here

(另外,你的标 checkout 口在左边被称为新闻标签这一事实暗示了一个问题,因为在代码中这个标签被称为“标题”,如果你已经上钩了正确,我希望 Xcode 在左侧列表中也将其名称更改为“标题”。)

[我有一种模糊的感觉,您可能实际上有两个类,TNTopStoriesCollectionViewCell 和 TNTopNewsCellItem,而您对它们感到困惑...]

关于ios - 如何在 Storyboard 中使用自定义 UICollectionViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35275104/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap