我正在尝试创建一个具有不同大小原型(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/