2016-07-05 93 views
1

我的tableView中只有一个cell。这cellfixed height。在这个cell下我有很多空的单元格,实际上不是单元格,并且是默认创建的。所有这些细胞都有separator所以在不难看出高度。如何更改tableView页脚中空单元格的高度?

如何使这些非单元格(在tableView页脚中)的高度不同于第一个cell的高度?

我试着使用heightForRowAtIndexPath

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 

    if indexPath.row == 0 { 
     return 140.0 
    } 
    return 70.0 
} 

,但我看到它被称为唯一真正的细胞,而不是tableView脚注单元。

回答

0

我没有找到真正的解决方案,所以我刚刚创建了看起来像单元格的tableView.tableFooterView

let unselectedCellHeight = CGFloat(70.0) 
    let screenHeight = UIScreen.mainScreen().bounds.size.height 
    let cellsAmount = Int(round(Float(screenHeight/unselectedCellHeight))) 
    let tableFooter = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: screenHeight)) 
    for i in 1...cellsAmount { 
     let view = UIView(frame: CGRect(x: 0, y: unselectedCellHeight*CGFloat(i), width: tableView.frame.size.width, height: 1)) 
     view.backgroundColor = UIColor.cellHeaderGrayColor() 
     tableFooter.addSubview(view) 
    } 
    self.tableView.tableFooterView = tableFooter