我正在使用 Pixate 来设置表格单元格的样式。我正在使单元格出列并更新 textLabel 类,如下所示:
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];
应用了类,但如果单元格出列,并且类发生变化,它不会始终生效。如何让风格始终保持不变?
更新:
首先我的症状描述是错误的。当我第一次加载表格时。没有单元格被设置样式。当我开始滚动时,样式已正确应用。当我滚动更多时,一些单元格(不是全部)的样式不正确。设置单元格值还应为:
// 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];
最初我使用的是 Pixate Freestyle 2.1.1。根据 pixatepaul 的提示,我更新到 2.1.3。2.1.3 表现出同样的问题。但是,在 2.1.1 下,我可以发誓该单元格应用了错误的样式。在 2.1.3 下,看起来错误的单元格没有得到任何样式。
updateStyle 建议也不起作用。
[cell updateStyle]; // Doesn't work
[cell.textLabel updateStyle]; // Doesn't work either
我在设置 textLabel 文本和样式时进行了一些日志记录,并且我注意到只有当一个出列单元格设置为它已经具有的相同值时才会出现问题。因此,我尝试了以下hack并且成功了。
// 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];
}
更新 2:
我查看了其他 table-view-cell 样式,看看是否有其他设置颜色的样式。我看到我正在设置颜色
table-view-cell text-label {
color: #53555a;
font-family: "Verdana";
font-size: 14pt;
font-weight: light;
}
删除颜色让我摆脱了 if 块和单元格的样式现在正确!
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];
//}