UITableView automati c высота строки (в зависимости от содержимого) - все та же ошибка - PullRequest
0 голосов
/ 19 июня 2020

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

[Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view. We're considering the collapse unintentional and using standard height instead. Cell: <ProjectSammy.AnnotationCell: 0x106061d80; baseClass = UITableViewCell; frame = (0 647.5; 414 70); autoresize = W; layer = <CALayer: 0x282d09ee0>> 

Думаю, я выполнил все требования (как указано в этом сообщении: { ссылка }):

Я полностью ограничиваю (верхняя и нижняя привязки) метки в моей настраиваемой ячейке:

    private func configureContents() {
        backgroundColor = .clear
        separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        
        contentView.addSubviews(titleLabel, detailsLabel)
        
        NSLayoutConstraint.activate([
            titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor,constant: 5),
            titleLabel.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor),
            titleLabel.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor),
            titleLabel.bottomAnchor.constraint(equalTo: detailsLabel.topAnchor),
            
            detailsLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor),
            detailsLabel.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor),
            detailsLabel.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor),
            detailsLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
        ])
        
    }

Я установил для строк в TableView автоматическое c измерение:

    private func configureTableView() {
        tableView = UITableView(frame: view.bounds, style: .grouped)
        view.addSubview(tableView)
        tableView.delegate = self
        tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        tableView.backgroundColor = .clear
        
        tableView.register(AnnotationCell.self, forCellReuseIdentifier: AnnotationCell.reuseIdentifier)
        tableView.register(AnnotationHeaderCell.self, forHeaderFooterViewReuseIdentifier: AnnotationHeaderCell.reuseIdentifier)
        
        tableView.sectionHeaderHeight = 40
        tableView.rowHeight = UITableView.automaticDimension
        tableView.estimatedRowHeight = 70
    }

И я даже указываю приблизительную высоту строки в методе делегата: -NOT NEEDED1- можно выполнить напрямую в tableview!

Где я go не прав?

1 Ответ

1 голос
/ 19 июня 2020

Расчетная высота строки не может быть установлена ​​автоматически c размер. Вы должны установить его на конкретное c число, попробуйте установить его на 44, что по умолчанию является высотой строки.

...