0

I am using Pixate to style table cells. I am dequeuing cells and updating the textLabel class like so:

    static NSString *CellIdentifier = @"Cell";
UITableViewCell * cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

cell.textLabel.text = @"Hello";
    // The dictionary is passed in.
cell.textLabel.styleClass = [dictionary objectForKey:STYLE_CLASS];

The class is applied, but if the cell is dequeued, and the class changes, it does not consistently take effect. How do I get the style to always get set?

Update:

Firstly the description of my symptoms is wrong. When I first load the table. No cells are styled. As I started scrolling, the styles are correctly applied. As I scroll around more, some cells, not all, get styled incorrectly. Setting the cell values should also read:

// Not sure why I got rid of this and replaced with @"Hello"
cell.textLabel.text = [dictionary objectForKey:NAME]; 
cell.textLabel.styleClass = [dictionary objectForKey:STYLE_CLASS];

Originally I was using Pixate Freestyle 2.1.1. On pixatepaul's hint I updated to 2.1.3. 2.1.3 exhibits the same problem. However, under 2.1.1 I could have sworn that cell had the wrong style applied. Under 2.1.3 it looked like the erroneous cells were not getting any style.

Also the updateStyle suggestion does not work.

[cell updateStyle]; // Doesn't work
[cell.textLabel updateStyle]; // Doesn't work either

I put some logging around setting the textLabel text and style, and I noticed that the problem only occurred if a dequeued cell was getting set to the same value it already had. So I tried the following hack and it worked.

// This can't be right.
if(![[dictionary objectForKey:NAME] isEqualToString:cell.textLabel.text])
{
    cell.textLabel.text = [dictionary objectForKey:NAME]; 
    cell.textLabel.styleClass = [dictionary objectForKey:STYLE_CLASS];
}

Update 2:

I had a look at other table-view-cell styles to see if there were any others that set color. I saw that I was setting the color in

table-view-cell text-label {
    color: #53555a;
    font-family: "Verdana";
    font-size: 14pt;
    font-weight: light; 
}

Removing the color let me get rid of the if block and cells are now styled properly!

table-view-cell text-label {
    font-family: "Verdana";
    font-size: 14pt;
    font-weight: light; 
}

//if(![[dictionary objectForKey:NAME] isEqualToString:cell.textLabel.text])
//{
    cell.textLabel.text = [dictionary objectForKey:NAME]; 
    cell.textLabel.styleClass = [dictionary objectForKey:STYLE_CLASS];
//}
Megasaur
  • 626
  • 8
  • 20
  • Is `STYLE_CLASS` just placeholder text for describing your question, or is it an actual constant in your code? If it's a constant, you will have the same `styleClass` over and over. What is the CSS you are applying to `cell.textLabel`? – Clifton Labrum Apr 29 '14 at 05:57
  • STYLE_CLASS is a key to get the style from my dictionary. I can see in the debugger that this gets set correctly. – Megasaur Apr 29 '14 at 12:03

2 Answers2

0

I'm curious which version you are using of Freestyle? You shouldn't need to, but you can call

[cell updateStyles]

after setting the styleClass.

pixatepaul
  • 251
  • 2
  • 5
  • Thanks for the suggestion. Calling updateStyle did not work. However, I updated from 2.1.1 to 2.1.3 and did some poking around and found some weird behaviour and a poor solution. Any further thoughts? – Megasaur Apr 29 '14 at 12:47
0

So I wanted to add a class to a text label in a cell to change the text color. I was just adding a class, no css selectors.

The style was not taking effect. Old CSS:

.benchmark {
    color: deeppink;
}

table-view-cell {
    background-color: #fff;
}

table-view-cell text-label {
    font-family: "Verdana";
    font-size: 14pt;
    font-weight: light;
    color: #53555a;
}

Maybe my specificity understanding is not good. Solution:

.benchmark {
    color: deeppink;
}

table-view-cell {
    background-color: #fff;
}

table-view-cell text-label {
    font-family: "Verdana";
    font-size: 14pt;
    font-weight: light;
}

And now cells are coloured correctly.

Megasaur
  • 626
  • 8
  • 20