iOS 7 UITableView: How to remove space between navigation bar and first cell

IosUitableviewIos7

Ios Problem Overview


Description of the problem: with iOS 7 in grouped UITableView there is a gap between the top of the table view and the first cell.

The strange part is that when I load the content for the first time the table appears to be ok (first image), but when I scroll down a space appears between top and first cell (second image):

enter image description here enter image description here

With style plain this behavior does't occur but unfortunately I need to use the grouped table view style.

Any ideas about?

Ios Solutions


Solution 1 - Ios

Just add this in you ViewDidLoad method

self.automaticallyAdjustsScrollViewInsets = NO;

Solution 2 - Ios

The answer was very funny for me and my team, and worked like a charm

  • In the Interface Builder, Just move the tableview under another view in the view hierarchy.

REASON:

We observed that this happens only for the First View in the View Hierarchy, if this first view is a UITableView. So, all other similar UITableViews do not have this annoying section, except the first. We Tried moving the UITableView out of the first place in the view hierarchy, and everything was working as expected.

Solution 3 - Ios

Go to the attributes inspector of the View Controller by selecting the xib or the controller in Storyboard. Uncheck the Adjust Scroll View Insets in Layout. It will solve the problementer image description here

Solution 4 - Ios

If you are using a UITableView with grouped style and only 1 group, use plain style instead solve your problem.

UITableViewController *tableViewController;
tableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

Solution 5 - Ios

Simplest solution to this problem in grouped type tableView is:

tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];

Solution 6 - Ios

For solve this problem make sure that you unchecked this field on ViewController:

On ViewController >> Attibutes Inspector >> Layout (unchecked - Adjust Scroll View Insets)

enter image description here

if this is not enough, try this on TableView, set Style to Plain:

Example image

This will solve your problem

Solution 7 - Ios

guys! I had the same problem. TableView appeared with free space between nav bar and first cell. This code saved me:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 10;
    }
    else return 2;
}

Solution 8 - Ios

There was a space above the UITableView itself, and also between the cells. Found my solution in 2 different answers above..posting it again so that nobody misses both solutions.

This removed the space from above :

self.automaticallyAdjustsScrollViewInsets = NO;

and this removed the spaces below the cells : Setting the 'Style' attribute of the UITableView to 'Plain'

Solution 9 - Ios

I am working with Xcode 7.3.1, iOS9, and swift 2. I would like to share what worked for me:

Just add this in you ViewDidLoad method

self.automaticallyAdjustsScrollViewInsets = false;

Solution 10 - Ios

Starting in iOS 7, you automatically get a group header and some space. Compare your app to the Settings app and you'll see. You can work around it by telling the UITableView to set the header height as small as possible. See How to hide first group header.

Solution 11 - Ios

I realize this was answered a long time ago, but for anyone else running into a similar situation, I'll share what ended up working for me:

If you're using a xib, select the top level view and set 'Status Bar' to 'None' in the Simulated Metrics area of the Attributes Inspector. Fixed my spacing issue right up.

Solution 12 - Ios

For me this didn't work

self.automaticallyAdjustsScrollViewInsets = NO;

This only caused the table view to sit under the NavigationBar.

What worked for me was to go into my storyboard, and resize my tableView. It seems my tableView had a 20px gap at the top to allow for the statusBar. I scaled it and everything lined up perfectly.

Solution 13 - Ios

I was seeing this extra space at the top of one of my table views in a very strange situation.

After I added a UIScrollView as the root view of my first controller in my navigation stack, if I presented the next controller as a Show Detail segue, my next controller would have the space above its table view.

The solution for me was to change the segue to Present Modally and everything went back to normal.

The strangest part of the segue changing was that before I added my root view being a UIScrollView, my Show Detail segue was presenting the next controller modally. Yet after I added the root UIScrollView, the Show Detail segue was pushing on the next controller (which was not what I wanted).

Solution 14 - Ios

Had a similar problem, even setting automaticallyAdjustsScrollViewInsets to NO. This solved for me:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
{
    return CGFLOAT_MIN;
}

Solution 15 - Ios

In the UIViewController.h iOS9 SDK have a method:

@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets NS_AVAILABLE_IOS(7_0); // Defaults to YES

is not a property, so

self.automaticallyAdjustsScrollViewInsets = NO; 

should be

-(BOOL)automaticallyAdjustsScrollViewInsets{   
     return NO;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFryView Question on Stackoverflow
Solution 1 - IosSlavchoView Answer on Stackoverflow
Solution 2 - IosGiorgos AthView Answer on Stackoverflow
Solution 3 - IosMuhammad_AwaabView Answer on Stackoverflow
Solution 4 - IosclmntcrlView Answer on Stackoverflow
Solution 5 - IosVenu Gopal TewariView Answer on Stackoverflow
Solution 6 - IosDaniel BeltramiView Answer on Stackoverflow
Solution 7 - IosHot'n'YoungView Answer on Stackoverflow
Solution 8 - Ioslove2script12View Answer on Stackoverflow
Solution 9 - IosIPL10View Answer on Stackoverflow
Solution 10 - IosChuck KrutsingerView Answer on Stackoverflow
Solution 11 - IosLukeView Answer on Stackoverflow
Solution 12 - IosvinylDeveloperView Answer on Stackoverflow
Solution 13 - IosAdam JohnsView Answer on Stackoverflow
Solution 14 - IosiuricernovView Answer on Stackoverflow
Solution 15 - Ios刘志余View Answer on Stackoverflow