2015-05-11 37 views
7

我似乎有一個奇怪的問題,我的一個桌面我不能隱藏分隔線(我認爲它們是分隔線,除了它們在屏幕上居中而不是很難對抗右手邊)。Swift Tableview總是顯示分隔線

我以編程方式創建所有東西,所以沒有故事板問題在這裏。

您可以在下面的每個單元格上方看到小小的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) 

我也有我實現使用下面的代碼自定義標題:

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:

現在我已經添加分隔線在和這些都不是分隔,因爲你仍然可以看到他們的分隔線下方。

enter image description here

HELP!我很困惑。我有一些其他的tableviews設置相同(據我所知),他們工作得很好。

謝謝!

+0

您是否檢查過您的自定義單元格的背景顏色是否正確? –

+0

嘿馬泰奧 - 我已經更新了這個問題,以顯示如何格式化單元格。另外,如果我刪除該代碼並且有標準單元格,它們將顯示灰色線條。我確定這些不是分隔線,因爲它們通常與右邊對齊不是他們?我很難過。必須有我做過的事情,因爲我的tableview代碼被保存爲片段。我剛剛重新啓動了XCode,但無法正常工作。 – bwash70

+0

是不是我們看到的默認色調顏色?作爲一個測試,請嘗試設置contentView的bg顏色:'cell.contentView.backgroundColor = ...' –

回答

4

由於您未使用自定義單元格,因此需要執行以下操作。

創建細胞是爲let cell : UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Subtitle, reuseIdentifier:"cell")

並刪除您的viewDidLoad()函數self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

+0

謝謝,完美@amit89 – bwash70

7

您可以使用表格視圖屬性爲seperatorStyle和使用屬性這樣UITableViewCellSeparatorStyleNone

,或者使用從故事板

enter image description here

設置分隔符的以財產上取下分離無

還有一件事,當您使用頁眉和頁腳,因此分隔線將爲零,但可能有一個額外的分隔符或標題和foo ter請參閱此鏈接 Eliminate extra separators below UITableView

+0

嗨 - 我沒有使用故事板,並且已經嘗試過使用tableview.separatorStyle = UITableViewCellSeparatorStyle.None。我已經看到了你發佈的鏈接,這是在tableview中填充的單元格之下的多餘行 - 這不會發生在我身上。 – bwash70

4

,補充一點:

tableView.tableFooterView = UIView() 
1

下面是關於消除雜散隔板用一些額外的信息可能會有所幫助。發端所述加工的解決方案是這一個,創建一個新的小區:

let cell : UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Subtitle, reuseIdentifier:"cell") 

但發端沒有說他是如何工作到他的代碼,它的原始版本使用dequeueReusableCellWithIdentifier的兩個參數版本:

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

我經歷虛假分離的同樣的問題,發現使用dequeueReusableCellWithIdentifier的單參數版本還修復了問題:

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