Swift Tableview始终显示分隔线

bwa*_*h70 8 uitableview ios swift

我似乎有一个奇怪的问题,我的一个表格视图,我无法隐藏分隔线(我认为它们是分隔线,除了它们在屏幕上居中而不是在右手边硬盘).

我以编程方式创建所有内容,因此没有故事板问题.

您可以在下面的每个单元格上方看到微小的1px线.

问题截图

我使用以下方式加载表:

    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)
Run Code Online (Sandbox Code Playgroud)

我还有一个自定义标头,我使用以下代码实现:

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()

}
Run Code Online (Sandbox Code Playgroud)

我已经尝试加载表没有,willDisplayHeaderView并且问题仍然存在.

我也尝试过添加

tableview.separatorStyle = UITableViewCellSeparatorStyle.None 
Run Code Online (Sandbox Code Playgroud)

tableView.separatorColor = UIColor.clearColor()
Run Code Online (Sandbox Code Playgroud)

以下方法:

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
}
Run Code Online (Sandbox Code Playgroud)

编辑:

这些单元格是标准的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
}
Run Code Online (Sandbox Code Playgroud)

编辑2:

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

在此输入图像描述

救命!我糊涂了.我有许多其他的表格视图设置相同(据我所知),他们工作正常.

谢谢!

Fat*_*han 7

您可以使用表视图属性,seperatorStyle并使用该属性UITableViewCellSeparatorStyleNone

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

在此输入图像描述

将Seperator的属性设置为None

或者在使用页眉和页脚时更多一点,因此分隔线将为零,但可能有一个额外的分隔符或页眉和页脚,所以请参阅此链接 消除UITableView下面的额外分隔符


小智 7

在viewDidLoad()函数中,添加以下内容:

tableView.tableFooterView = UIView()
Run Code Online (Sandbox Code Playgroud)


Ami*_*t89 4

由于您没有使用自定义单元格,因此您需要执行以下操作。

创建单元格为let cell : UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Subtitle, reuseIdentifier:"cell")

并删除self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")