开发者

table rows leaking

开发者 https://www.devze.com 2023-01-13 19:27 出处:网络
i have the following rows in an iphone table view and they sometimes leak the text from one of the rows to another.

i have the following rows in an iphone table view and they sometimes leak the text from one of the rows to another.

if (row <1)
    {
        cell.detailTextLabel.text=@"h3ello";
             UIImage *image = [UIImage imageNamed:@"icon.png"];
           cell.imageView.image = image;   
    }
      else if (row ==2)
    {
        cell.detailTextLabel.text=@"world";
        UIImage *image = [UIIm开发者_高级运维age imageNamed:@"ticon.png"];
        cell.imageView.image = image
}

and sometimes these images get screwed up in between and also i have another row that includes a text color. This causes various and random rows get the red color when i am scrolling. im not sure what the error is..

EDIT

This is the culprit involved

 cell.textLabel.textColor = [UIColor redColor];

once i remove this none of the rows get mixed up with the colors. how can i implement this color to a specific row without it leaking onto the others randomly.


Because cells by default are reusable you should always set ALL parameters for ALL cells you ever used. If you want to change color for one cell you should set default color for OTHER cells too. So use cell.textLabel.textColor = .... in each case with proper color.


The reason Skie gives is correct. Let me clarify it a little more:

cell.textLabel.text = @"";
cell.textLabel.textColor = [UIColor clearColor];
cell.imageView.image = nil;

if (row <1)
{
    cell.detailTextLabel.text=@"h3ello";
    UIImage *image = [UIImage imageNamed:@"icon.png"];
    cell.imageView.image = image;   
}
  else if (row ==2)
{
    cell.detailTextLabel.text=@"world";
    UIImage *image = [UIImage imageNamed:@"ticon.png"];
    cell.imageView.image = image
} else {
}
0

精彩评论

暂无评论...
验证码 换一张
取 消