静态表视图与单元格填充可见的屏幕区域

时间:2016-03-03 13:28:15

标签: ios uitableview swift2

我想创建一个包含7个单元格的静态表格,其中包含状态栏和导航栏,以填充屏幕的其余部分。我重写了下面的方法,但我没有得到预期的结果。我缺少什么?

    override func tableView(tableView:UITableView, heightForRowAtIndexPath indexPath:NSIndexPath) -> CGFloat {
    let tableHeight = (CGFloat(tableView.bounds.height) - CGFloat(64))/7

    return tableHeight }

图片显示我的7个单元格没有占据所有屏幕static table view with 7 cells

2 个答案:

答案 0 :(得分:1)

试试这个

override func tableView(tableView:UITableView, heightForRowAtIndexPath indexPath:NSIndexPath) -> CGFloat {
    let tableHigh = (CGFloat(UIScreen.mainScreen.bounds.height) - CGFloat(64))/7

    return tableHigh }

答案 1 :(得分:0)

这是另一个很好的解决方案:

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

    let tableHeight = (tableView.bounds.height - tableView.contentInset.top - tableView.contentInset.bottom) / 7

    return tableHeight
}
相关问题