tableView中的自定义静态单元与其他原型单元格

时间:2015-07-31 19:06:52

标签: swift uitableview custom-cell

通过这些行我创建了一个表格视图,第一个单元格为静态,另一个原型为

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);我试过检查员,但运行项目不起作用。是否有其他方法可以通过编程方式增加静态单元高度?

1 个答案:

答案 0 :(得分:0)

只需使用tableView(_:heightForRowAtIndexPath:)

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