Я пытаюсь написать UITableViewController без Storyboard с классом, который определяет UITableViewCell.
Я настроил табличное представление как требуется с
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 200.0
tableView.register(HomeCell.self, forCellReuseIdentifier: "cell")
и создал HomeCell
класс UITableViewCell только с иконкой.
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
icon = UIImageView(frame: CGRect.zero);
icon.translatesAutoresizingMaskIntoConstraints = false;
contentView.addSubview(icon)
}
Я вставил в класс func для Auto layout и с помощью debug определил, что функция вызывается:
override func layoutSubviews() {
icon.heightAnchor.constraint(equalToConstant: 50).isActive = true
icon.widthAnchor.constraint(equalToConstant: 50).isActive = true
icon.leftAnchor.constraint(equalTo: contentView.leftAnchor,
constant: 5).isActive = true
icon.topAnchor.constraint(equalTo: contentView.topAnchor,
constant: 5).isActive = true
contentView.bottomAnchor.constraint(equalTo: icon.bottomAnchor, constant: 5).isActive = true
}
В результате у меня есть значок в правильном положении, но contentView
имеет неправильную высоту, то есть исходный размер 44, установленный UITableViewAutomaticDimension, и последовательные строки перекрываются.
Кто-то имеет представление о том, что не так?