3

On iOS 11, the cell edit actions or swipe actions(available only for iOS 11) are being displayed on top of the section headers, if the table view style is set to plain (not grouped). This seems to be the default functionality and I'm wandering if this is a system bug or maybe my implementation is wrong.

I implemented a demo app, using a default table view implementation and the following functions for the headers and edit action rows:

Title for Header:

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return "Section \(section)"
    }

Edit actions for row:

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let firstAction = UITableViewRowAction(style: .normal, title: "Action1", handler: {_,_ in })
        let secondAction = UITableViewRowAction(style: .destructive, title: "Action2", handler: {_,_ in })
        return [firstAction, secondAction]
    }

Trailing swipe action(the new implementation only available on iOS 11):

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let action1 = UIContextualAction(style: .normal, title: "Action1", handler: {_,_,_ in })
        let action2 = UIContextualAction(style: .destructive, title: "Action2", handler: {_,_,_ in })
        return UISwipeActionsConfiguration(actions: [action1, action2])
    }

Here is a screenshot of how the edit actions are being displayed: Edit action overlapping section header

This only happens on iOS 11. I have tried using both methods mentioned above alternatively, but I am getting the same results.

Do you have an idea of how I might be able to fix this? Is this an iOS 11 system bug?

frozencure
  • 181
  • 1
  • 9
  • looks like it happens on iOS 11.4 only. At least for me in that case. – Pratik Mistry Jul 27 '18 at 06:07
  • I have tested this on other versions of iOS and it also happens on 11.2.2 for me, so I think it is a iOS 11 general issue – frozencure Aug 06 '18 at 08:56
  • yeah just tested on iOS 11.3 and you are right @frozencure seems like iOS 11 only – Pratik Mistry Aug 06 '18 at 09:53
  • @PratikMistry Do you think maybe we're doing something wrong and this might not be a system bug? I've looked for apps which run on iOS 11 and have plain tableviews with row actions but I haven't been able to find any. – frozencure Aug 06 '18 at 10:39
  • 1
    possible we are doing something wrong but so far it looks like a system bug to me. As same thing seems to be working fine in iOS 9 and iOS 10 – Pratik Mistry Aug 06 '18 at 11:42
  • 1
    Just ran into this issue myself :( working on iOS 9, 10 but not 11. Any ideas for a workaround? – kd02 Aug 20 '18 at 09:33
  • Did you find anything? I've got this problem on iOS 11.4 – mikro098 Sep 20 '18 at 09:21
  • @codddeer123 See the answer below, it seems it triggers another bug but as soon as kd02 finds a solution you should be good to go. – frozencure Sep 20 '18 at 10:26
  • Hey I am using this but this is not working for Section, it is only swipable for rows – A.s.ALI May 22 '19 at 05:32

1 Answers1

3

For anybody that comes across this issue I found a workaround by subclassing UITableViewHeaderFooterView class and then setting the layer's zPostion to 1 which will change the header's view ordering within the window's view rendering which solved it for me.

Solution 1:

open class HeaderFooterView: UITableViewHeaderFooterView {

    public override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)

        if #available(iOS 11.0, *) {
            self.layer.zPosition = 1;
        }
    }
}

Alternative workaround if you don't want to subclass the UITableViewHeaderFooterView class is to just override viewForHeaderInSection delegate method then set the view's zPosition before returning it.

Solution 2:

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "CustomHeader") as! CustomHeader

    headerView.title = "Header title"

    if #available(iOS 11.0, *) {
         headerView.layer.zPosition = 1;
    }

    return headerView
}
kd02
  • 422
  • 5
  • 14
  • 1
    I believe this solution will trigger another bug: the scroll bar will appear below the section header, because the scroll bar's zPosition is 0. You can see the `UICollectionView` counterpart of the bug [here](https://stackoverflow.com/q/46694144/1111252), where the solution is to set the header view's zPosition back to 0 (which would cause this question's bug to resurface). – peco Sep 19 '18 at 11:00
  • 1
    Yes @peco you are correct, I'm able to replicate the bug with the scrollbar appearing behind the header. I'm going to try find at a fix for this. Thank you for letting me know. – kd02 Sep 19 '18 at 11:37
  • Hey I am using this but this is not working for Section, it is only swipable for rows – A.s.ALI May 22 '19 at 05:32