ios - 选择单元格时 UITableView 分隔符颜色发生变化

标签 ios swift uitableview

我创建了一个 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 但无事可做,当单元格被选中时它保持白色。请参阅下面的示例(在此示例中选择了最后一个单元格)...

example of the problem

最佳答案

cellForRowAtIndexPath 方法中尝试此代码行

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

希望这对您有所帮助。

关于ios - 选择单元格时 UITableView 分隔符颜色发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40126756/

相关文章:

ios - 将UitableViewCell分成两种颜色

ios - 将 UIToolbar 添加到 UICollectionView header ?

iphone - 为什么带有几个按钮的基本 UIScrollView 不会滚动?

sqlite - 在 iOS 项目中管理 coredata/sqlite 数据库生命周期

ios - UITabBarItem - 将图像与标题文本分开放置

ios - 初学者 : How to present UITableView programmatically from another view

ios - 如何在不使用 Storyboard的情况下在 UITableView 中使用静态单元格?

ios - 如何制作一个确认某个协议(protocol)并具有不同父类的对象数组?

swift - swift 隐藏协议(protocol)的采用

ios - UIViewController 中带有 TableViewCell 的 TableView 不显示来自 SearchBar 的数据