UIContextMenuInteraction giving NSLayoutConstraint warnings when interacting and shifting the tableView lower down

225 Views Asked by At

I have a UITableView to display a series of data in different cells. I've added a UIContextMenuInteraction to the tableView so that I can interact with each cell and get a preview. When I perform the interaction on any cell, it first gives a bunch of constraint warnings. In the warnings it mentions about a groupView which I never reference or access, unless it is default context menu stuff.

Also when exiting the interaction the tableView acts weird by shifting the tableView lower down before going back to normal - see here: https://streamable.com/3g5byj


Code:

extension ProjectsViewController: UIContextMenuInteractionDelegate {
    private func setupContextMenuInteraction() {
        let interaction = UIContextMenuInteraction(delegate: self)
        tableView.addInteraction(interaction)
    }

    func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
        guard let indexPath = tableView.indexPathForRow(at: location), let _ = tableView.cellForRow(at: indexPath) else { return nil }
        let project = projects[indexPath.section]

        return UIContextMenuConfiguration(identifier: "\(indexPath.section)" as NSCopying, previewProvider: {
            let projectViewController = ProjectViewController(project: project)
            return projectViewController
        }) { actions -> UIMenu? in
            let favourite = UIAction(title: "Favourite", image: UIImage(systemName: "star"), identifier: nil) { _ in
            }

            let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up"), identifier: nil) { _ in
                guard let url = URL(string: project.url) else { return }

                let activityController = UIActivityViewController(activityItems: [url], applicationActivities: nil)

                DispatchQueue.main.async {
                    self.present(activityController, animated: true, completion: nil)
                }
            }

            return UIMenu(title: "", children: [favourite, share])
        }
    }
}

Constraint warning:

2020-05-16 19:56:40.398521+0200 MyApp[2690:219904] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x600002b75180 h=--& v=--& UIInterfaceActionGroupView:0x7fc782c500f0.height == 0   (active)>",
    "<NSLayoutConstraint:0x600002b79950 groupView.actionsSequence....height >= 66   (active, names: groupView.actionsSequence...:0x7fc78311c800 )>",
    "<NSLayoutConstraint:0x600002b794f0 UIInterfaceActionGroupView:0x7fc782c500f0.top == _UIContentConstraintsLayoutGuide:0x7fc782c4eb30''.top   (active)>",
    "<NSLayoutConstraint:0x600002b79540 V:[_UIContentConstraintsLayoutGuide:0x7fc782c4eb30'']-(0)-|   (active, names: '|':UIInterfaceActionGroupView:0x7fc782c500f0 )>",
    "<NSLayoutConstraint:0x600002b79f40 groupView.actionsSequence....top == _UIContentConstraintsLayoutGuide:0x7fc782c4eb30''.top   (active, names: groupView.actionsSequence...:0x7fc78311c800 )>",
    "<NSLayoutConstraint:0x600002b79f90 groupView.actionsSequence....bottom == _UIContentConstraintsLayoutGuide:0x7fc782c4eb30''.bottom   (active, names: groupView.actionsSequence...:0x7fc78311c800 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600002b79950 groupView.actionsSequence....height >= 66   (active, names: groupView.actionsSequence...:0x7fc78311c800 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
0

There are 0 best solutions below