如何保护UITableViewCell的文本,UITableViewCell在滚动时被更改。保护UITableView滚动事件的cell.textLabel.text
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,@ “要设置静态文本” 会被覆盖上@ “MyCustomLabel”。
我该如何预防?我希望UITableView的所有单元通过Table的LifeTime保留它们的TextLabels。
但是,它改变了我的“MyCustomLabel”到“设置静态文本“(这是另一个单元格的文本)。 – Krishna 2012-02-13 16:40:51
是的,这就是应该发生的事情。它只发生在细胞不再可见时。你可以通过为静态单元使用不同的重用标识符来阻止它。正如我在答复中所说的那样。 – 2012-02-13 16:48:21
什么也没有改变,即使在创建新的reuseIdentifier之后。 – Krishna 2012-02-13 17:10:12