我的一个 tableview 似乎有一个奇怪的问题,我无法隐藏分隔线(我认为它们是分隔线,除了它们在屏幕上居中而不是靠在右手上边)。
我以编程方式创建所有内容,因此这里没有 Storyboard问题。
您可以在下面的每个单元格上方看到 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)
我还有一个使用以下代码实现的自定义 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:
我现在添加了分隔线,这些不是分隔线,因为您仍然可以在分隔线下方看到它们。
帮助!我很困惑。我有许多其他的 tableviews 设置相同(据我所知)并且它们工作正常。
非常感谢!
最佳答案
您可以为 seperatorStyle
使用 Table View 属性,也可以像这样使用属性 UITableViewCellSeparatorStyleNone
或者使用从 StoryBoard 中移除分隔符
将Seperator的属性设置为None
或者在您使用页眉和页脚时还有一件事,因此分隔线将为零,但可能会有额外的分隔符或页眉和页脚,因此请参阅此链接 Eliminate extra separators below UITableView
关于ios - Swift Tableview 总是显示分隔线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30159554/