gpt4 book ai didi

iphone - 在 UITableView 的滚动事件上保护 cell.textLabel.text

转载 作者:行者123 更新时间:2023-11-28 23:06:17 24 4
gpt4 key购买 nike

如何保护 UITableViewCell 的文本,它在 UITableView 滚动时发生变化。

static NSString *CellIdentifier = @"Cell";
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(indexPath.row != [destinationList count])
{
if (cell == nil)
{
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.customLable.text = @"MyCustomLabel";
else
{
if (cell == nil)
{
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"Static Text to be set";
[cell.customLable removeFromSuperview];
}

问题: 每次我滚动 UITableView 时,@"Static Text to be set"都会被 @"MyCustomLabel"覆盖。

我该如何防止这种情况发生?我希望 UITableView 的所有单元格在 Table 的生命周期内保留它们的 TextLabel。

最佳答案

两个可能的答案:

  1. 一般来说这无关紧要。重复使用单元格是它应该如何工作的,你应该每次都完全“重置”每个单元格。无论如何你都不应该在单元格中存储状态
  2. 创建一个新的 reuseIdentifier,一个用于自定义标签,另一个用于静态文本

关于iphone - 在 UITableView 的滚动事件上保护 cell.textLabel.text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9260797/

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