我似乎有一個奇怪的問題,我的一個桌面我不能隱藏分隔線(我認爲它們是分隔線,除了它們在屏幕上居中而不是很難對抗右手邊)。Swift Tableview總是顯示分隔線
我以編程方式創建所有東西,所以沒有故事板問題在這裏。
您可以在下面的每個單元格上方看到小小的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)
我也有我實現使用下面的代碼自定義標題:
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用alter顏色交替的細胞,這被設置爲通過:
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:
現在我已經添加分隔線在和這些都不是分隔,因爲你仍然可以看到他們的分隔線下方。
HELP!我很困惑。我有一些其他的tableviews設置相同(據我所知),他們工作得很好。
謝謝!
您是否檢查過您的自定義單元格的背景顏色是否正確? –
嘿馬泰奧 - 我已經更新了這個問題,以顯示如何格式化單元格。另外,如果我刪除該代碼並且有標準單元格,它們將顯示灰色線條。我確定這些不是分隔線,因爲它們通常與右邊對齊不是他們?我很難過。必須有我做過的事情,因爲我的tableview代碼被保存爲片段。我剛剛重新啓動了XCode,但無法正常工作。 – bwash70
是不是我們看到的默認色調顏色?作爲一個測試,請嘗試設置contentView的bg顏色:'cell.contentView.backgroundColor = ...' –