tags:

views:

41

answers:

2

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 = [UIImage 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.

+2  A: 

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.

Skie
meaning add an extra else statement to set the default color and text.
VdesmedT
+1  A: 

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 {
}
vodkhang