UITableViewCell 中的 UIButtons 不显示 textLabel 更改,直到单元格滚出屏幕

Posted

技术标签:

【中文标题】UITableViewCell 中的 UIButtons 不显示 textLabel 更改,直到单元格滚出屏幕【英文标题】:UIButtons in UITableViewCell do not show textLabel changes until cells scroll off screen 【发布时间】:2015-06-22 21:58:27 【问题描述】:

我有一个带有日历的 UIViewController,它下面是一个带有 UITableViewCell 的 UITableView,它有一系列 UIButton,我根据检索到的数据更改按钮文本。选择日期后,我更新 NSArray 并调用 [self.tableView reloadData]。第一行按应有的方式填充,UIButton 标题显示正确的数据。其余行显示情节提要中 UIButtons 的默认值。如果我从屏幕上滚动一个单元格并让它回来,它会显示正确的数据(即更新 UIButtons 的标题)。我不确定为什么会这样。我尝试添加 [cell setNeedsLayout] 在返回单元格之前,但它没有帮助。

【问题讨论】:

你是直接修改testLabels吗?如果你这样做,UIButtons 有时会有不确定的行为。尝试使用 UIButton 方法更改 textLabel 的属性,例如 setTitle: forState: 好建议,但没有解决问题。 @Aderis 实际上您的建议确实有效。我在如何实现它时犯了一个错误。谢谢。 【参考方案1】:

你是直接修改 testLabels 吗?如果你这样做,UIButtons 有时会有不确定的行为。尝试使用 UIButton 方法更改 textLabel 的属性,例如 setTitle: forState:

【讨论】:

以上是关于UITableViewCell 中的 UIButtons 不显示 textLabel 更改,直到单元格滚出屏幕的主要内容,如果未能解决你的问题,请参考以下文章

如何更改 UIButton 标题?

更改 UITableViewCell 中的对象也更改了重用 UITableViewCell 的对象

确定 UITableViewCell 中的 UIButton

UITableViewCell 事件中的 UIButton 不起作用

UITableViewCell 中的 UICollectionView

UITableVIewCell 中的 UIScrollView 不会滚动