Как исправить ошибку «Невозможно одновременно удовлетворить ограничения» или отладку журналов (SnapKit) - PullRequest
0 голосов
/ 06 ноября 2019

Я создал динамическую высоту ячейки табличного представления с AutoLayout, используя SnapKit. Все выглядит хорошо, когда я создаю приложение ( Result image ), но я получаю некоторые странные сообщения отладки, и я не знаю, в чем проблема в моем коде.

Я попытался setContentCompressionResistancePriority (.defaultHigh, для: .vertical), make.bottom.equalTo (self.contentView) .offset (-10) .priority (999), но проблема та же. Прямо сейчас я понятия не имею. Вот как я настраиваю myView:

Я настраиваю myView в ячейке:

В init:

contentView.addSubview(myview)
override func updateConstraints() {
        if !upCon {
            myview.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
            myview.snp.makeConstraints { (make) in
                make.top.equalTo(self.contentView).offset(10)
                make.left.equalTo(self.contentView).offset(10)
                make.width.height.equalTo(50)
                make.bottom.equalTo(self.contentView).offset(-10).priority(999)
            }
            upCon = true
        }
        super.updateConstraints()
    }

Я устанавливаю высоту строки следующим образом:

myView.tableView.estimatedRowHeight = 100
myView.tableView.rowHeight = UITableView.automaticDimension

Так что я не хочу видеть это в журнале отладки (если вам нужно больше кода, чтобы воспроизвести проблему, я могу поделиться другим кодом):

[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. 
(
    "<SnapKit.LayoutConstraint:0x28127c8a0@ViewController.swift#35 UIView:0x1053738e0.top == UITableViewCellContentView:0x105373e50.top + 10.0>",
    "<SnapKit.LayoutConstraint:0x28127c9c0@ViewController.swift#37 UIView:0x1053738e0.height == 50.0>",
    "<SnapKit.LayoutConstraint:0x28127ca20@ViewController.swift#38 UIView:0x1053738e0.bottom == UITableViewCellContentView:0x105373e50.bottom - 10.0>",
    "<NSLayoutConstraint:0x2815540f0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x105373e50.height == 70.5   (active)>"
)

Will attempt to recover by breaking constraint 
<SnapKit.LayoutConstraint:0x28127c9c0@ViewController.swift#37 UIView:0x1053738e0.height == 50.0>

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.
2019-11-06 17:28:04.738171+0200 testImageRotation[19361:1301631] [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. 
(
    "<SnapKit.LayoutConstraint:0x28127cf60@ViewController.swift#35 UIView:0x105376a60.top == UITableViewCellContentView:0x105370a40.top + 10.0>",
    "<SnapKit.LayoutConstraint:0x28127d080@ViewController.swift#37 UIView:0x105376a60.height == 50.0>",
    "<SnapKit.LayoutConstraint:0x28127d0e0@ViewController.swift#38 UIView:0x105376a60.bottom == UITableViewCellContentView:0x105370a40.bottom - 10.0>",
    "<NSLayoutConstraint:0x281554730 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x105370a40.height == 70.5   (active)>"
)

Will attempt to recover by breaking constraint 
<SnapKit.LayoutConstraint:0x28127d080@ViewController.swift#37 UIView:0x105376a60.height == 50.0>

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.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...