2016-07-05 88 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