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];
//}