The Cook
The Cook

Reputation: 1443

How to get rid of empty space before UITableView?

I have a UITableView in a UIViewController in a UINavigationController in a UITabBarController.

In my UITableView, I have section headers, and all sections have 60 pixel height. Set like this.

tableView.sectionHeaderHeight = 60

My UITableView also have Grouped for style attribute.

The problem is, there is empty space above my UITableView and I want to get rid of it.

The problem only occurs on iPads, there is no empty space on smaller devices. (I simulated on iPad 2 and iPhone 6 respectively.) Because of this solution #3 does not work.

Some of the solutions I have tried but did NOT work:

  1. self.automaticallyAdjustsScrollViewInsets = false
  2. tableView.contentInset = UIEdgeInsetsZero
  3. self.tableView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0)

Does not work for all devices. Because my table already works good in some devices and this makes it go out of screen on them.

  1. Setting UITableView style to Plain instead of Grouped.

This works, but I need my headers to be Grouped style not plain. So I can't use this.

So what are my options here? Thanks in advance.

Edit: Screenshot:Ss1 Ss2

Upvotes: 2

Views: 289

Answers (2)

Ratul Sharker
Ratul Sharker

Reputation: 8011

Change the UITableView's Style property to plain in interface builder, like following.

enter image description here

Upvotes: 1

vaibhav
vaibhav

Reputation: 4096

You need to uncheck adjust scrollview insets property by selecting relevant viewController see below image:

enter image description here

Hope this helps.

Upvotes: 1

Related Questions