- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 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()
})
不需要为高度实现任何其他方法。这通过根据所选值动态增加多选择器行的高度解决了我的问题。
关于ios - 根据选择显示所有选定值的动态高度 MultipleSelectorRow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55584542/
我正在尝试自定义由 MultipleSelectorRow 呈现的 Controller 背景,但我不能。 ("select") { row in row.options = values
我正在用 Eureka 做过滤器表单。所以有一个包含所有类别的列表,前面还有一个“全部”单元格。所以我的问题是,当我按下“全部”时,如何立即取消选择所有其他单元格以及如何在单击其他单元格时取消选择“全
我正在使用 Eureka 构建一个表单,其中我们从列表中选择多个值,并且我们需要显示在表单上选择的所有值。我为此使用了 MultipleSelectorRow,但没有选项可以根据内容动态增加单元格的大
这是一个与名为 Eureka 的 Swift 开源项目相关的问题。并且我在 SO 上发布了这个问题,因为他们在这里监视他们的标签。 我创建了一个表单,其中有一个 MultipleSelectorRow
我有以下代码: form.last! () { $0.title = field.question $0.options = []
我的用例描述了用户可以在其中选择从 A 到 F 的多个阶段的字段的必要性。为了实现这一点,我使用了 MultipleSelectorRow n Eureka 库: ("phase") {
谁能帮我从 Eureka 表单的 MultipleSelectorRow 中检索值? 我有一个像这样的多选行,其中列出了楼层。 { $0.title = " *Floo
我是一名优秀的程序员,十分优秀!