gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:54:43 28 4
gpt4 key购买 nike

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

TNTopStoriesCollectionViewController:

static NSString * const reuseIdentifier = @"TNTopNewsCellItem";

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)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

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

最佳答案

在场景中对象的分层名称列表中,此单元格在左侧上称为“ Collection View 单元格”,并且没有更改为“头条新闻 Collection View 单元格”这一事实表明您实际上没有成功地将 Storyboard中的类更改为 TNTopStoriesCollectionViewCell。

(注意 Collection View Controller 如何列在左侧作为头条新闻 Collection View Controller 。同样的事情应该发生在单元格上。)

您在左侧看到的应该更像这样:

enter image description here

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

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

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com