LettersBa
LettersBa

Reputation: 767

Navigation bar influence UITableViewController

I have a UITableViewController connected with a UINavigationController in my storyboard. when I scroll down my table I can see the rows going to the back side to the "navigation bar".

Making a brief check, I realized that the navigation bar are not influencing the table size (It appears that the navigation bar is in front of my table). Since when I select the table size:

-(CGFloat)tableView:(UITableView *)tableViews heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    CGFloat value = tableViews.frame.size.height;

    NSLog(@"Table size -> %f",value);

    return value/2;

}

He returns the same size os my window... what I could do to make the "navigation bar" to influence the size of my table?

Upvotes: 0

Views: 142

Answers (1)

rmaddy
rmaddy

Reputation: 318814

You have a few options. Try one of the following:

  1. Subtract the height of the nav bar and status bar from the table view frame height.

    CGFloat value = tableViews.frame.size.height - CGRectGetMaxY(self.navigationController.navigationBar.frame);
    
  2. Don't put the table view behind the navigation bar. Fix this by adding the following line to your table view controller's viewDidLoad:

    self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeRight;
    

    This prevents the table view from going under the nav bar or toolbar.

One more note. If you want all rows to have the same height, don't implement the heightForRowAtIndexPath method. Instead, simply set the table view's rowHeight property.

Upvotes: 1

Related Questions