0

我正在使用 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];
//}
4

2 回答 2

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.

于 2014-04-28T12:45:48.430 回答
0

所以我想在单元格的文本标签中添加一个类来更改文本颜色。我只是添加一个类,没有 CSS 选择器。

样式没有生效。旧的 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;
}

也许我的特异性理解不好。解决方案:

.benchmark {
    color: deeppink;
}

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

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

现在单元格的颜色正确。

于 2014-07-05T01:23:04.467 回答