I\'m trying to remove the separator for one UITableViewCell
. I did the following:
- (UITableViewCell *)tableView:(UITableView *)tableView cellFo
If you'd like to show separator to only the visible cell you can try this:
tableView.separatorInset = UIEdgeInsets(top: 0, left: 1000, bottom: 0, right: 0)
let visibleCell = tableView.visibleCells
for cellV in visibleCell{
cellV.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
Swift 3 remove separator all cell:
override func viewDidLoad() {
self.yourTableView.separatorStyle = UITableViewCellSeparatorStyle.none
}
Just add following to the cell you don't want separator (swift 3) :
override func awakeFromNib() {
super.awakeFromNib()
// remove separator
self.separatorInset = UIEdgeInsetsMake(0, 1000, 0, 0)
}
You can just visually hide separator through separatorInset
property:
tableViewCell.separatorInset = UIEdgeInsets(top: 0, left: 10000, bottom: 0, right: 0)
For those people struggling with this for iOS 9 the solution is a little different than the answers already given. Here is how I solved it in Swift:
override func viewWillAppear(animated: Bool) {
table.cellLayoutMarginsFollowReadableWidth = false
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if IS_THE_CELL_WITH_NO_SEPARATOR{
cell.separatorInset = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins = UIEdgeInsetsZero
}
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if IS_THE_CELL_WITH_NO_SEPARATOR{
let size = self.view.bounds.size
let rightInset = size.width > size.height ? size.width : size.height
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, rightInset)
}
}
Assign next values for specific cell you need for customization.
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, .greatestFiniteMagnitude)
cell.directionalLayoutMargins = .zero