irkinosor
irkinosor

Reputation: 776

Static Table View with Cell that fill visible screen area

I want to create a static table with 7 cells that fill the rest of the screen with taking into account the status bar and nav bar. I override the methods bellow but I am not getting the expected result. What I am missing?

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

    return tableHeight }

the picture shows that my 7 cells do no occupy all the screen static table view with 7 cells

Upvotes: 0

Views: 288

Answers (2)

irkinosor
irkinosor

Reputation: 776

This is another good solution:

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

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

    return tableHeight
}

Upvotes: 0

techloverr
techloverr

Reputation: 2617

try this

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

    return tableHigh }

Upvotes: 1

Related Questions