我在该单元格中有自定义单元格和标签的动态高度。然后我添加新单元格,但所有单元格的高度都相等(相同)。我的代码:
class MyTable: UITableViewController {
var height: CGFloat = 0.0
/* ........ */
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let row = indexPath.row
/* make some action with objects in cell */
let cell = tableView.dequeueReusableCellWithIdentifier("order", forIndexPath: indexPath) as! OrderData
self.height = cell.address_lbl.frame.origin.y + cell.address_lbl.frame.height + 8
return cell
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return self.height
}
}
我明白,这个问题是重复的,但我不知道如何制作动态高度。 附言该解决方案必须适用于 iOS 7
最佳答案
这不是代码的问题,代码正在执行您编写的内容。逻辑有问题, TableView 数据源方法未按您预期的顺序调用。您应该将高度计算移动到 heightForRowAtIndexPath
以使单元格具有不同的高度。
关于ios - UITableView 中自定义单元格的动态高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35721501/