0

There's a white gap above the first cell of my table view that disappears when you interact with the view in any way. The gap is as high as the navigation bar. I already tried self.automaticallyAdjustsScrollViewInsets = false and using a 0 by 0 view as the header. The first method does nothing and the second one produces glitched results.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Pixel
  • 171
  • 2
  • 10

3 Answers3

0

Apply

[self.navigationController setNavigationBarHidden:YES]; 

and

self.automaticallyAdjustsScrollViewInsets = false; 

as you said. This works for me.

Ah, one more thing. Important

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


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return HEIGHT_DEFAULT_TABLE_FOOTER;
}

These two methods can adjust height of header and footer for the table view.

Hwangho Kim
  • 629
  • 4
  • 20
  • I don't want the navigation bar to be hidden so that wouldn't help. And I know how to change the header and footer heights, but the gap doesn't seem to have to do with those. – Pixel Aug 11 '16 at 00:24
  • FYI - the question is tagged Swift, not Objective-C. – rmaddy Aug 11 '16 at 00:32
  • Ok it's swift.., @Pixel BTW did you add it in viewDidLoad or somewhere? In my case I added it in viewDidLoad – Hwangho Kim Aug 11 '16 at 00:33
  • @HwanghoKim the linked answer helped. Thank you. I had to also set automaticallyAdjustsScrollViewInsets on the parent view controller. – Pixel Aug 11 '16 at 13:18
0

I have tried every possible solution and found it for iOS 11 and above use:

    self.tableView.contentInsetAdjustmentBehavior = .never
Nitin
  • 51
  • 1
  • 1
-1

This happened to me at one point. Try product -> clean project.

Also try restarting XCode.

If that doesn't work, try removing the header entirely. Why have a header at all if you are going to set its values to 0 by 0.

Also make sure the insets on the attributes inspector are also zero.

If none of these work, try the solution with the most work, which is to delete your UITableView entirely and adding it again :(

Aram H.B.
  • 104
  • 8