Два просмотра стека с одинаковыми настройками, но разными результатами - PullRequest
0 голосов
/ 05 ноября 2018

У меня есть две пользовательские ячейки tableView; один выполнен в лево-правом макете с изображением слева и многострочным ярлыком справа. У другого точно такая же вещь, но с надписью слева и изображением справа. Изображение и метка содержатся в виде стека в обоих случаях, и настройки идентичны: Axis = Horizontal, Alignment = Center, Distribution = Fill Proportionally, Spacing = 10. Обе метки имеют одинаковые ограничения макета; закрепленный сверху / снизу (для изменения размера ячейки) и width >= 100.

В случае, когда метка находится слева, ее ширина устанавливается равной нулю во время выполнения, и текст не появляется. Есть ли причина, по которой я не знаю, почему два порядка объектов будут вести себя по-разному.

ОБНОВЛЕНИЕ: Вот что я имею в методах делегата tableViewController:

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return "Help: The Basics"
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

// MARK: - Table view data source
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let item = items[indexPath.row]
    var cell: HelpTableViewCell? = nil
    switch item.layoutType {
    case .left:
        cell = tableView.dequeueReusableCell(withIdentifier: "HelpDefaultCell") as! HelpDefaultTableViewCell
    case .right:
        cell = tableView.dequeueReusableCell(withIdentifier: "HelpAlternateCell") as! HelpAlternateTableViewcell
    case .vertical:
        cell = tableView.dequeueReusableCell(withIdentifier: "HelpVerticalCell") as! HelpVerticalTableViewcell
    }
    cell!.uiImage.image = item.image
    if item.imageIsHidden {
        cell!.uiImage.isHidden = true
    }
    if indexPath.row == 0 {
        // this is the overview text -- no image!
        let text = item.helpString
        let formattedString = NSMutableAttributedString()
        formattedString
            .bold(text, size: 19.0)
        cell!.helpTextLabel.attributedText = formattedString
    } else {
        cell!.helpTextLabel.text = item.helpString
    }
    return cell as! UITableViewCell
}

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return items.count
}

override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    (view as! UITableViewHeaderFooterView).backgroundView?.backgroundColor = UIColor.lightGray
}

enter image description here enter image description here

Я (очевидно, достаточно) получаю конфликт:

2018-11-05 09:32:01.284852-0800 xxx[7760:2416718] [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:0x2825fcf50 UILabel:0x14ddca540'Touch the xxx graphic t...'.width >= 100   (active)>",
"<NSLayoutConstraint:0x2825fce10 'fittingSizeHTarget' UILabel:0x14ddca540'Touch the xxx graphic t...'.width == 0   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x2825fcf50 UILabel:0x14ddca540'Touch the xxx graphic t...'.width >= 100   (active)>

Я смущен этим, потому что у меня нет никаких ограничений .width == 0. Они должны быть добавлены автоматически, я полагаю? (Несмотря на эту ошибку, данная ячейка отображается правильно.)

ОБНОВЛЕНИЕ: я могу настроить его так, как я хочу, и избежать ошибок макета, выбрав Equal Centering вместо Fill Proportionally. Кто знает ...

...