【问题标题】:UITableView separator color changing when cell selected选择单元格时 UITableView 分隔符颜色发生变化
【发布时间】:2016-10-19 09:02:30
【问题描述】:

我创建了一个 UITableView,但分隔符有问题。我对其进行了自定义,使其显示为灰色且没有插图:

self.tableView.separatorInset = .zero
self.tableView.separatorColor = AppColors.separatorColor

我也尝试了一张图片:

self.tableView.separatorInset = .zero
tableView.separatorStyle = UITableViewCellSeparatorStyle.singleLine
tableView.separatorColor = UIColor(patternImage: #imageLiteral(resourceName: "thin_divider"))

问题:选择行时,分隔符变为白色。我玩了 didSelectRowAtdidDeselectRowAtdidHighlightRowAt 但无事可做,当单元格被选中时它保持白色。请参见下面的示例(此示例中选择了最后一个单元格)...

【问题讨论】:

  • 您确定它是分隔符,而不仅仅是表格视图和下一个视图之间的 1 像素间隙吗?因为在您的图像上,它只显示在最后一个单元格之后,而不是每个单元格之后。
  • @smeshko 是的,当然,因为在图像上我选择了最后一个单元格,但如果我选择任何其他单元格,分隔符也会变成白色
  • @Mrunal 是的,谢谢,它解决了问题,但按下时不再突出显示单元格

标签: ios swift uitableview


【解决方案1】:

cellForRowAtIndexPathmethod 中试试这个代码行

[cell setSelectionStyle: UITableViewCellSelectionStyleNone];

这会将none设置为选择样式(此属性的默认值为UITableViewCellSelectionStyleBlue)。

对于单元格高亮部分,请在didSelectRowAtIndexPath 中使用以下代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setHighlighted: NO];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
} 

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 2013-10-13
    • 2012-03-08
    相关资源
    最近更新 更多