ios - UITableView 中自定义单元格的动态高度

标签 ios uitableview

我在该单元格中有自定义单元格和标签的动态高度。然后我添加新单元格,但所有单元格的高度都相等(相同)。我的代码:

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/

相关文章:

android - ionic 闪屏尺寸

javascript - iOS 13.3 PWA 上的相机错误

objective-c - 创建自定义 UITableViewCell

ios - 使用 UITableViewAutomaticDimension 制作带有嵌入式 UICollectionView 的 UITableView

ios - 如何在 Objective C 中调整 UITableView 行高

ios - 不能在属性初始值设定项中使用实例成员 'movies1',属性初始值设定项在 'self' 可用之前运行

ios - UITableViewCell 子类不允许我设置标签文本

ios - 在 [NSRunLoop(NSRunLoop) runMode :beforeDate:] 中发生奇怪的崩溃

iphone - 在 UILabel 中追加字符串?

html - 在 UIWebview 中嵌入 youtube