【问题标题】:Dynamically Resize one Static Table View Cell's Height in Swift在 Swift 中动态调整一个静态表格视图单元格的高度
【发布时间】:2017-05-14 12:44:53
【问题描述】:

我正在尝试按照标题建议的方式根据用户设备的高度动态分配某个高度。我现在有一个 8 静态单元格的表格视图,在最后一个表格视图中,它包含一个容器视图,指向另一个动态单元格的表格视图控制器,图片发布在下面。到目前为止,一切都通过故事板完成,但是,因为我无法像其他元素一样“约束”单个单元格,我希望在这里找到解决我的问题的方法。基本上在最后一个单元格中,静态单元格必须根据“用户手机的高度”的坐标动态改变其高度 - “第 7 个静态单元格的 Y 坐标”是我的想象。

【问题讨论】:

    标签: swift uitableview


    【解决方案1】:

    据我了解,如果除最后一个之外所有单元格的高度都相同,那么您要做的就是实现 heightForRowAtIndexPath 方法。对于最后一个单元格,您进行所需的计算。我给你举个例子

        func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        if indexPath.row == 8 {
            //Returns UITableViewAutomaticDimension or the size you have calculated
            return UITableViewAutomaticDimension
        } else {
            return x.x
        }
    }
    
    func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        if indexPath.row == 8 {
            //Returns UITableViewAutomaticDimension or the size you have calculated
            return UITableViewAutomaticDimension
        } else {
            return x.x
        }
    }
    

    【讨论】:

    • 您是否建议 UITableViewAutomaticDimension 是一个可行的选择?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 2016-07-13
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多