Получение ошибки ограничения при свертывании раздела Tableview - PullRequest
0 голосов
/ 17 января 2019

У меня есть пользовательский вид ячейки, который содержит изображение и метку, встроенную в вертикальный вид стека.

Stack View связан с 4 краями Content View.

Изображение имеет ограничение 1: 1.

Операции развертывания и свертывания, кажется, работают нормально, однако, пока я продолжаю нажимать, я вижу некоторые предупреждения в какой-то момент, и это кажется случайным.

cell preview expanded row

2019-01-17 23:15:46.749683+0300 MyApp[10270:349316] [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. 
(
    "<NSLayoutConstraint:0x6000032e54a0 UIStackView:0x7f9f97d19620.height == 43.5   (active)>",
    "<NSLayoutConstraint:0x6000032e5590 V:[UIStackView:0x7f9f97d19620]-(5)-|   (active, names: '|':UITableViewCellContentView:0x7f9f97d19430 )>",
    "<NSLayoutConstraint:0x6000032e5630 V:|-(5)-[UIStackView:0x7f9f97d19620]   (active, names: '|':UITableViewCellContentView:0x7f9f97d19430 )>",
    "<NSLayoutConstraint:0x6000032e5f40 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7f9f97d19430.height == 499.5   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000032e54a0 UIStackView:0x7f9f97d19620.height == 43.5   (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.

Что я запускаю, чтобы развернуть / свернуть, так это:

....
tableView.register(UINib(nibName: "InboxTableViewCell", bundle: nil), forCellReuseIdentifier: "inboxCell")
        tableView.rowHeight = UITableView.automaticDimension
        tableView.estimatedRowHeight = 500
        tableView.reloadData()
....

func numberOfSections(in tableView: UITableView) -> Int {
        return tableViewData.count
    }


    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        if tableViewData[section].opened == true {
            return tableViewData[section].sectionData.count + 1
        }else  {
            return 1
        }
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row == 0 {

            let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell", for: indexPath) as! HeaderTableViewCell
            return cell
        } else {
            let cell = tableView.dequeueReusableCell(withIdentifier: "inboxCell", for: indexPath) as! InboxTableViewCell

            return cell
        }
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 0{
            if tableViewData[indexPath.section].opened == true {
                tableViewData[indexPath.section].opened = false
                let sections = IndexSet.init(integer: indexPath.section)
                tableView.reloadSections(sections, with: .none)

            }else{
                tableViewData[indexPath.section].opened = true
                let sections = IndexSet.init(integer: indexPath.section)
                tableView.reloadSections(sections, with: .none)

            }
        }
    }

1 Ответ

0 голосов
/ 17 января 2019

Установите приоритет ограничения изображения 1: 1 равным 999 или ниже.Это заставляет Auto Layout генерировать ограничение высоты для стекового представления, чтобы поддерживать соотношение сторон.Это плохо для бизнеса.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...