通过这些行,我创建了一个带有第一个静态单元格和其他原型(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/