如何保護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