【问题标题】:Row Height of UITableView Custom Cell doesn't update, Swift iOS8UITableView 自定义单元格的行高不更新,Swift iOS8
【发布时间】:2016-02-04 03:00:46
【问题描述】:

我在 iOS 8 的 Xcode 6.4 的 Storyboard 中创建了一个 UITableView 自定义单元格。当我在 Storyboard 的 Size Inspector enter image description here 中更改行高时,应用程序中我的 UITableView 的自定义单元格没有任何反应。

【问题讨论】:

    标签: swift uitableview ios8 custom-cell xcode6.4


    【解决方案1】:

    您可以通过在 TableViewController 中覆盖此方法来更新它:

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 55
    }
    

    【讨论】:

    • 是的,我知道这种方式,但我的 UITableView 中有几个不同高度的不同单元格
    • @PhilippJanuskovecz 您可以使用'indexPath'为每个单元格返回不同的值
    【解决方案2】:

    在你的 tableview 控制器的这个方法中:

    override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell?
    

    确保添加这一行:

    cell.height = yourHeight
    

    【讨论】:

      【解决方案3】:

      您可以在 Storyboard 的 Table View 中添加 Table View Cell Prototype 并将您的 Prototype Cell 拖到底部,您可以获得所需的高度单元格。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-12
        • 1970-01-01
        • 2021-09-17
        • 2011-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-26
        相关资源
        最近更新 更多