Код: Выделить всё
import UIKit
import SnapKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let tableView = UITableView(frame: .zero, style: .plain)
let sections = ["Lorem","Lorem Ipsum","Lorem Ipsum is simply dummy text.","Lorem Ipsum is simply dummy text of the printing and typesetting industry."]
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(SectionHeader.self, forHeaderFooterViewReuseIdentifier: "SectionHeader")
tableView.sectionHeaderHeight = UITableView.automaticDimension
tableView.estimatedSectionHeaderHeight = UITableView.automaticDimension
view.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
tableView.dataSource = self
tableView.delegate = self
}
func numberOfSections(in tableView: UITableView) -> Int {
sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")
cell.textLabel?.text = "Index \(indexPath.row)"
cell.detailTextLabel?.text = "Section \(indexPath.section)"
return cell
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! SectionHeader
let attr = NSAttributedString(string: sections[section], attributes: [.font: UIFont.preferredFont(forTextStyle: .extraLargeTitle)])
header.sectionTitle.setAttributedTitle(attr, for: .normal)
header.setNeedsLayout()
header.layoutIfNeeded()
return header
}
}
class SectionHeader: UITableViewHeaderFooterView {
let sectionTitle = UIButton()
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
sectionTitle.contentHorizontalAlignment = .left
contentView.addSubview(sectionTitle)
let padding = 10.0
sectionTitle.snp.makeConstraints { make in
make.left.equalToSuperview().inset(padding)
make.right.equalToSuperview().inset(padding)
make.top.equalToSuperview().inset(padding)
make.bottom.equalToSuperview().inset(padding)
if let t = sectionTitle.titleLabel {
t.numberOfLines = 0
t.lineBreakMode = .byWordWrapping
t.adjustsFontForContentSizeCategory = true
make.height.equalTo(t)
}
}
}
}

Однако Xcode продолжает печатать приведенный ниже UIViewAlertForUnsatisfiableConstraints Невозможно одновременно удовлетворить ограничения предупреждения:
Код: Выделить всё
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.
(
"",
"",
""
)
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
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.
(
"",
"",
""
)
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
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.
(
"",
"",
""
)
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
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.
(
"",
"",
""
)
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
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.
(
"",
"",
""
)
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
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.
(
"",
"",
""
)
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
Ограничения на UITableViewHeaderFooterView приводят к UIViewAlertForUnsatisfiableConstraints
Однако я уже реализовал решение оттуда по настройке разделаHeaderHeight и AssessmentSectionHeaderHeight на UITableView.automaticDimension, и я все еще получаю предупреждения.
Я также пытался установить приоритет нижних и правых ограничений раздела Title на .low, но затем текст просто исчезает с экрана.
Фактический макет выглядит хорошо, поэтому я думаю, что мне не хватает чего-то простого. Как мне предотвратить эти предупреждения?
Подробнее здесь: https://stackoverflow.com/questions/798 ... iviewalert
Мобильная версия