具有UIContextMenuConfiguration的iOS UITableViewCell:无法同时满足约束

时间:2020-07-06 13:32:49

标签: ios swift uitableview autolayout

长按UITableViewCell时,我跟随this tutorial中的raywenderlich.com显示上下文菜单,并提出了以下简化版本来测试实现:

import UIKit

class ViewController: UITableViewController {
        
    override func tableView(
        _ tableView: UITableView,
        contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint)
        -> UIContextMenuConfiguration? {

            let identifier = "\(indexPath.row)" as NSString
            
            return UIContextMenuConfiguration(
                identifier: identifier,
                previewProvider: nil) { _ in
                    
                    let shareAction = UIAction(
                        title: "Share",
                        image: UIImage(systemName: "square.and.arrow.up")) { _ in
                            print("share")
                    }

                    return UIMenu(title: "", image: nil, children: [shareAction])
            }
    }
}

ViewController是简单的UITableViewController,在情节提要中带有静态单元格。当我运行应用程序并长按表格单元格时,代码将按预期工作,但是在控制台中出现以下AutoLayout错误,我不明白为什么?

2020-07-06 15:22:36.879780+0200 Test[1033:453998] [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:0x282308780 h=--& v=--& UIInterfaceActionGroupView:0x102833490.width == 0   (active)>",
    "<NSLayoutConstraint:0x28231bca0 UILabel:0x102921c50'Share Item'.leading == UILayoutGuide:0x283939420'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x28231bcf0 UILabel:0x102921c50'Share Item'.trailing == UILayoutGuide:0x283939420'UIViewLayoutMarginsGuide'.trailing   (active)>",
    "<NSLayoutConstraint:0x282315db0 _UIInterfaceActionGroupHeaderScrollView:0x103063600.width == _UIPreviewPlatterActionsTitleView:0x102921590'Share Item'.width   (active)>",
    "<NSLayoutConstraint:0x28231a800 H:|-(0)-[_UIContentConstraintsLayoutGuide:0x1028336f0'']   (active, names: '|':UIInterfaceActionGroupView:0x102833490 )>",
    "<NSLayoutConstraint:0x28231a850 _UIContentConstraintsLayoutGuide:0x1028336f0''.trailing == UIInterfaceActionGroupView:0x102833490.trailing   (active)>",
    "<NSLayoutConstraint:0x28232fd40 _UIInterfaceActionGroupHeaderScrollView:0x103063600.width == _UIContentConstraintsLayoutGuide:0x1028336f0''.width   (active)>",
    "<NSLayoutConstraint:0x28231cfa0 'UIView-leftMargin-guide-constraint' H:|-(12)-[UILayoutGuide:0x283939420'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIPreviewPlatterActionsTitleView:0x102921590'Share Item' )>",
    "<NSLayoutConstraint:0x28231bc50 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x283939420'UIViewLayoutMarginsGuide']-(12)-|(LTR)   (active, names: '|':_UIPreviewPlatterActionsTitleView:0x102921590'Share Item' )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x28231bcf0 UILabel:0x102921c50'Share Item'.trailing == UILayoutGuide:0x283939420'UIViewLayoutMarginsGuide'.trailing   (active)>

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.
2020-07-06 15:22:36.881528+0200 Test[1033:453998] [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:0x2823088c0 h=--& v=--& UIInterfaceActionGroupView:0x102833490.height == 0   (active)>",
    "<NSLayoutConstraint:0x28231b070 groupView.actionsSequence....height >= 44   (active, names: groupView.actionsSequence...:0x103062e00 )>",
    "<NSLayoutConstraint:0x2823135c0 V:[_UIInterfaceActionGroupHeaderScrollView:0x103063600]-(0)-[_UIInterfaceActionVibrantSeparatorView:0x10283ab40]   (active)>",
    "<NSLayoutConstraint:0x2823140a0 V:[_UIInterfaceActionVibrantSeparatorView:0x10283ab40]-(0)-[groupView.actionsSequence...]   (active, names: groupView.actionsSequence...:0x103062e00 )>",
    "<NSLayoutConstraint:0x28231ada0 UIInterfaceActionGroupView:0x102833490.top == _UIContentConstraintsLayoutGuide:0x1028336f0''.top   (active)>",
    "<NSLayoutConstraint:0x28231adf0 V:[_UIContentConstraintsLayoutGuide:0x1028336f0'']-(0)-|   (active, names: '|':UIInterfaceActionGroupView:0x102833490 )>",
    "<NSLayoutConstraint:0x282314190 _UIInterfaceActionGroupHeaderScrollView:0x103063600.top == _UIContentConstraintsLayoutGuide:0x1028336f0''.top   (active)>",
    "<NSLayoutConstraint:0x2823141e0 groupView.actionsSequence....bottom == _UIContentConstraintsLayoutGuide:0x1028336f0''.bottom   (active, names: groupView.actionsSequence...:0x103062e00 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x28231b070 groupView.actionsSequence....height >= 44   (active, names: groupView.actionsSequence...:0x103062e00 )>

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 个答案:

没有答案