iosswiftuitableviewuiswipeactionsconfiguration

UITableView, UISwipeActionsConfiguration, UIContextualAction - The pullView is not in a view hierarchy. This is a UIKit bug


I have a UITableView with swipe action that when swiping: A) displays a blank/empty area where the swipe action button should display; and B) the following line is logged to the debug console in Xcode:

[Assert] The pullView is not in a view hierarchy. This is a UIKit bug.

As of today, zero Google results exist for searching on the title of this question.


Solution

  • It turns out that the culprit was the following

    override func setEditing(_ editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
    
        if !editing {
            rowSelectionState.removeAll()
            loadData()
        }
        refreshView()
    }
    

    Specifically, the refreshView() call, which contains a tableView.reloadData() call, needs to be inside of the if !editing { ... } block. If not, when a swipe action is initiated, the swipe action appears to call setEditMode(true, ...), thus calling tableView.reloadData() which messes with the UISwipeActionsConfiguration's ability to be properly displayed.

    Thus the above should look like this:

    override func setEditing(_ editing: Bool, animated: Bool) {
        super.setEditing(editing, animated: animated)
    
        if !editing {
            rowSelectionState.removeAll()
            loadData()
            refreshView()
        }
    }