fredpi
fredpi

Reputation: 8952

Separator line unexpectedly appears when swiping UITableViewRowActions away

In my app I'm using a UITableView which consists of multiple headers and one or two rows for each header. Each cell features two UITableViewRowActions. My problem is, that whenever these row actions are animated out, a strange separator appears between the cell and the header underneath.

I've tried turning off the default separators, and using a custom separator instead, but for some reason I actually need to use the default separators.

In the next step I tried to disable the separator only for those cells which are on top of the next header, like this, but it didn't work:

if #available(iOS 9.0, *) {

      tableView.cellLayoutMarginsFollowReadableWidth = false

  }

cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
cell.separatorInset.left = self.view.frame.size.width

To help you gain an impression of the issue, I've created three screenshots that show the strange behaviour:

Before:

enter image description here

While displaying row actions:

enter image description here

After dismissing row actions using tableView.setEditing(false, animated: true):

enter image description here

Do you have any idea how I can remove this strange separator line?

Upvotes: 2

Views: 591

Answers (1)

fredpi
fredpi

Reputation: 8952

I finally found a relatively clean solution to fix this issue - I just add a "line fix" view to every header view, that will overlay the strange separator. Since it seems to be an Apple bug, that's probably the best workaround.

Here's the code:

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let view = UITableViewHeaderFooterView()

    let lineFix = UIView(frame: CGRect(x: 0, y: -0.5, width: tableView.frame.size.height, height: 0.5))
    lineFix.backgroundColor = UIColor.groupTableViewBackgroundColor()
    view.addSubview(lineFix)

    return view

}

Upvotes: 3

Related Questions