ios - Swift Tableview 总是显示分隔线

标签 ios uitableview swift

我的一个 tableview 似乎有一个奇怪的问题,我无法隐藏分隔线(我认为它们是分隔线,除了它们在屏幕上居中而不是靠在右手上边)。

我以编程方式创建所有内容,因此这里没有 Storyboard问题。

您可以在下面的每个单元格上方看到 1px 的细线。

Screenshot of issue

我使用以下方式加载我的表:

    self.tableView.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
    self.tableView.dataSource = self
    self.tableView.delegate = self
    self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    self.tableView.backgroundColor = UIColor.whiteColor()
    self.tableView.scrollEnabled = true
    self.tableView.bounces = false
    self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
    self.view.addSubview(self.tableView)

我还有一个使用以下代码实现的自定义 header :

func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {

    let header:UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView

    header.textLabel.textColor = UIColor.whiteColor()
    header.textLabel.frame = header.bounds
    header.textLabel.textAlignment = NSTextAlignment.Center

    view.tintColor = constants.getTintColor()
    header.textLabel.textColor = UIColor.whiteColor()

}

我尝试在没有 willDisplayHeaderView 的情况下加载表格,但问题仍然存在。

我也试过添加

tableview.separatorStyle = UITableViewCellSeparatorStyle.None 

tableView.separatorColor = UIColor.clearColor()

以下方法:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

    tableView.separatorStyle = UITableViewCellSeparatorStyle.None

}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {

    tableView.separatorStyle = UITableViewCellSeparatorStyle.None

    return self.boards.count
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    tableView.separatorStyle = UITableViewCellSeparatorStyle.None

    return self.boards[section].items.count
}

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?
{
    tableView.separatorStyle = UITableViewCellSeparatorStyle.None

    return self.boards[section].name
}

编辑:

单元格是标准的 UITableViewCells,单元格颜色交替,这是通过以下方式设置的:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

    let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell

    cell.selectionStyle = UITableViewCellSelectionStyle.None

    if indexPath.row % 2 == 0 {
        // Even
        cell.backgroundColor = constants.UIColorFromRGB(0x1EACE0)
    } else {
        // Odd
        cell.backgroundColor = constants.UIColorFromRGB(0x6FBEE5)
    }

    cell.textLabel?.textColor = UIColor.whiteColor()
    cell.textLabel?.text = self.boards[indexPath.section].items[indexPath.row].title

    return cell
}

编辑 2:

我现在添加了分隔线,这些不是分隔线,因为您仍然可以在分隔线下方看到它们。

enter image description here

帮助!我很困惑。我有许多其他的 tableviews 设置相同(据我所知)并且它们工作正常。

非常感谢!

最佳答案

您可以为 seperatorStyle 使用 Table View 属性,也可以像这样使用属性 UITableViewCellSeparatorStyleNone

或者使用从 StoryBoard 中移除分隔符

enter image description here

将Seperator的属性设置为None

或者在您使用页眉和页脚时还有一件事,因此分隔线将为零,但可能会有额外的分隔符或页眉和页脚,因此请参阅此链接 Eliminate extra separators below UITableView

关于ios - Swift Tableview 总是显示分隔线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30159554/

相关文章:

ios - 为什么点击 Today Notification Widget 中的按钮会导致整个 View 向左移动?

ios - UI 测试 - isSelected 总是返回 false

ios - 在 UIViewController 中使用 tableView 有什么好处?

ios - 更新 UITableView 单元格中的 UIImageView 透明度

ios - 使用 Swift 3 将大型 JSON 保存到 Realm

swift - 线程 1 : EXC_BAD_INSTRUCTION when encoding data in UserDefaults (Swift)

ios - 滚动时 TableView UILabel 对齐方式发生变化

ios - UICollectionView 仅显示数据集中的第一项

ios - TableView Load More 正在不停地获取

arrays - 准备 segue 数组时不包含任何数据(使用 swift)