Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the separator for only one section in a static UITableView?

I'm implementing a static TableView which has two sections in Swift. I want to have the same effect as UITableViewCellSeparatorStyle.None in only section 0, while remaining the separator in the other section. Since it is a static TableView, I cannot configure the cell in cellForRowAtIndexPath function (which always get a cell value nil). I tried to make some IBOutlet for each of the static cells and configure their seperatorInset and layoutMargins property, however it just doesn't work. So I would like to know if there are other ways to remove the separators? Thanks!

like image 560
whitney13625 Avatar asked Dec 09 '25 18:12

whitney13625


1 Answers

First add effect UITableViewCellSeparatorStyle.None To the tableView. After that you can add a small view in your cell Which looks like the separator. Then give the connection to the separator View with the cell.after that the only thing you have to do in the cellForRowAtIndexPath is

if(indexPath.section == 0) {
     seperatorView.hidden = false
} else {
     seperatorView.hidden = true
}

This is a small trick to solve your Problem. Hope it helps

like image 145
chakshu Avatar answered Dec 11 '25 09:12

chakshu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!