gpt4 book ai didi

ios - 在 collectionView :cellForItemAtIndexPath 外的 UICollectionViewCell 中更新 UILabel

转载 作者:行者123 更新时间:2023-12-01 17:54:56 24 4
gpt4 key购买 nike

我在 IB 中定义的 ViewController 中的 UICollectionView 中有一个自定义 UICollectionViewCell。在单元格中有一个标签,我可以在 cellForItemAtIndexPath 中设置和修改文本属性。我想要实现的是更改 UILabel 中选定单元格的文本属性。当在 didSelectItemAtIndexPath 中选择单元格时,我存储 indexPath。我想通过单击按钮( Collection View 外的按钮)进行更新并将 UILabel 的文本属性设置为按钮标题(pressedNumber)。

我试过这个:

-(BOOL) calculate: (NSString *) pressedNumber{

talCell *cell = [self.collectionView
dequeueReusableCellWithReuseIdentifier:@"cell"
forIndexPath:selectedCell];


[cell.cellTitle setText:pressedNumber];
[self.collectionView reloadItemsAtIndexPaths:@[selectedCell]];

调试时我可以看到 cell.cellTitle.text 属性与pressedNumber 相同。
感谢任何可以引导我找到正确代码的建议。

最佳答案

如果您有单元格的 indexPath,请使用 cellForItemAtIndexPath 获取它

talCell *cell = [self.collectionView
cellForItemAtIndexPath:indexPath];


[cell.cellTitle setText:pressedNumber];

关于ios - 在 collectionView :cellForItemAtIndexPath 外的 UICollectionViewCell 中更新 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19538031/

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