Я использую Eureka для создания формы, в которой мы выбираем несколько значений из списка, и нам нужно показать все значения, выбранные в форме. Я использую для этого MultipleSelectorRow, но нет возможности динамически увеличивать размер ячейки в соответствии с содержимым. Мы можем указать фиксированную высоту, но здесь мне нужно назначить динамическую высоту для ячейки. Пожалуйста, объясните, как этого можно достичь?
Я попытался указать фиксированную высоту, и она работает хорошо, но динамическое определение высоты ячейки не работает. Я даже пытался реализовать высоту строки UITableViewAutomaticDimension, но это тоже не работает.
<<< MultipleSelectorRow("aprovers") { row in
row.title = "Approvers"
row.options = requestedByArr
row.selectorTitle = "Select Approvers"
row.onPresent({ from, to in
// Decode the value in row title
to.selectableRowCellSetup = { cell, row in
// cell.height = ({return 60})
let size = row.cell.contentView.systemLayoutSizeFitting(UILayoutFittingCompressedSize)
row.cell.height = { size.height }
//row.cell.height = ({return UITableViewAutomaticDimension})
row.cell.detailTextLabel?.numberOfLines = 0
row.cell.contentView.setNeedsLayout()
row.cell.contentView.layoutIfNeeded()
row.reload()
self.tableView.reloadData()
if let value = row.selectableValue {
row.title = value
}
}
to.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: from, action: #selector(CategoryGroups.multipleSelectorDone(_:)))
})
row.onChange({ (row) in
//row.cell.height = ({return 100})
let size = row.cell.contentView.systemLayoutSizeFitting(UILayoutFittingCompressedSize)
row.cell.height = { size.height }
//row.cell.height = ({return UITableViewAutomaticDimension})
row.cell.detailTextLabel?.numberOfLines = 0
row.cell.contentView.setNeedsLayout()
row.cell.contentView.layoutIfNeeded()
row.reload()
self.tableView.reloadData()
})
}```
The expected results should be increased in cell's height as per the selected number of values from the multipleSelectorRow but the actually the height doesn't increase. If it increases, then UI gets distorted and data merge into the upper row.
Нам нужно реализовать
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 100
tableView.delegate = self
с методами
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
и добавьте следующие методы в MultipleSelectorRow
.cellSetup({ (cell, row) in
cell.detailTextLabel?.numberOfLines = 0
}).cellUpdate({ (cell, row) in
cell.detailTextLabel!.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
cell.detailTextLabel!.leftAnchor.constraint(equalTo: (cell.textLabel?.rightAnchor)!, constant: 15),
cell.detailTextLabel!.rightAnchor.constraint(equalTo: cell.contentView.rightAnchor, constant: -15),
cell.detailTextLabel!.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor, constant: -15),
cell.detailTextLabel!.topAnchor.constraint(equalTo: cell.contentView.topAnchor, constant: 15)
])
cell.updateConstraintsIfNeeded()
})
Нет необходимости реализовывать какой-либо другой метод для высоты. Это решило мою проблему за счет динамического увеличения высоты строки множественного селектора в соответствии с выбранными значениями.