swift - tableView 中的自定义静态单元格与其他原型(prototype)单元格

标签 swift uitableview custom-cell

通过这些行,我创建了一个带有第一个静态单元格和其他原型(prototype)的表格 View

override func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
    return 2
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    switch section
    {
    case 0 : return 1
    case 1 : return elenco.cori.count
    default : fatalError("No rows!")
    }
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    var cell : UITableViewCell!
    switch (indexPath.section)
    {
    case 0 :
        cell = tableView.dequeueReusableCellWithIdentifier("container", forIndexPath: indexPath) as! UITableViewCell
        cell.textLabel?.text = "Squadra"

    case 1 :
        cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
        let coro = elenco.cori[indexPath.row]
        cell.textLabel?.text = coro.marker
        cell.backgroundColor = UIColor.clearColor()
    default : fatalError("No cells!")
    }
        return cell
}

现在我想修改第一个单元格的高度(不是另一个单元格的 44,而是 120);我在检查器中尝试过,但运行该项目不起作用。是否有其他方法以编程方式增加静态单元格高度?

最佳答案

只需使用tableView(_:heightForRowAtIndexPath:)

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    switch indexPath.section {
        case 0: return 120
        case 1: return 44
        default: fatalError("...")
    }
}

关于swift - tableView 中的自定义静态单元格与其他原型(prototype)单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31753427/

相关文章:

swift - SWXMLHash EXC_BAD_INSTRUCTION(代码=EXC_I386_INVOP,子代码=0x0)

ios - iOS 8 中的 layoutMarginsFollowReadableWidth 错误

swift - 这是如何在 swift 4 中实现的?

ios - 在 Swift 中选择行时删除标签背景颜色

ios - CustomCell 中的 UISwitch 未更改特定索引路径处的值

swift - UINavigationController 后退按钮标题颜色

ios - 无法在 SpriteKit 中的坐标空间之间进行转换

ios - 使用 Realm Swift 进行变音符号不敏感过滤

ios - 如何在 Swift 中动态更改包含 UICollectionView 单元格的 UITableView 单元格的高度?

ios - 快速滚动ios时自定义单元格中的UITextField值出现问题