ios - Xcode TableView 单元格不会调整高度

标签 ios swift uitableview swift3

我正在尝试创建一个具有不同大小原型(prototype)单元格的 UITableView

我将表格 View 中的行高设置为 243。第一个和第二个单元格的单独行高分别设置为 243 和 465。当我运行我的应用程序时,两个单元格都显示在 243 高度处。

这是我尝试过的:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 25
}
//does not change cell height

和:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 25
}
//Method does not override any method from its superclass

如何配置我的项目以成功调整第二个单元格的大小?

最佳答案

委托(delegate)方法的签名在 Swift 3 中发生了变化。它需要:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.row == 1 {
        return 465.0
    } else {
        return 243.0
    }
}

使用错误的签名, TableView 不知道您已经实现了该方法,因此它永远不会被调用。

关于ios - Xcode TableView 单元格不会调整高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39761177/

相关文章:

ios - 如何在 iOS 上使用 PoDoFo 库来注释 PDF?

ios - 如何在 iOS 模拟器中调试 .app 崩溃?

ios - 在 Swift 2.0 中子类化 PFUser

swift - UILabel 的字体在 View 重新出现之前不会调整

ios - 快速在 UITABLEVIEW 上向右滑动时添加操作

iphone - 将UITableView变成UIImageView

ios - 平滑 MKPolyline 跟随道路

ios - Swift 2.0 子类化 UIViewController 的子类并调用便利初始化器

ios - iOS 中的线程通信?

java - 我可以将 'byte' 用于 boolean 数组吗?