gpt4 book ai didi

ios - 自定义 UICollectionViewCell 中的 UILabel 始终为空,无法更新文本

转载 作者:IT王子 更新时间:2023-10-29 08:17:24 25 4
gpt4 key购买 nike

我创建了一个对于 Apple Collection View 示例项目来说非常简单的 Collection View 。我在 Storyboard 的 View Controller 中有一个 Collection View ,并在 Collection View 右上角的 Collection View 单元格内设置了一个标签。我已将其连接到自定义单元格中的 IBOutlet。这是相关代码:

- (void)viewDidLoad
{
[super viewDidLoad];
[self.workoutView registerClass:[Cell class] forCellWithReuseIdentifier:@"Cell"];
...
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if (collectionView == self.collView) {
Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
cell.segmentTitle.text = @"some text";
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
return nil;
}

我在 segmentTitle.text 部分之后放置了一个断点,并且 segmentTitle 始终为 null。因此,我在模拟器中看到的是空的白框。我错过了什么?

最佳答案

StoryBoard 中的 UICollectionViewCell 不需要注册类,只需要在 StoryBoard 中选择 reuseidentifier。删除这一行:

   // [self.workoutView registerClass:[Cell class] forCellWithReuseIdentifier:@"Cell"];

并确保您以正确的方式连接:

-选择storyBoard中UICollectionViewCell的class类型为Cell

-将UILabel拖入Cell并挂接到Cell.h

-键入重用标识符

关于ios - 自定义 UICollectionViewCell 中的 UILabel 始终为空,无法更新文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15824225/

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