3

I'm trying to display my UITableView's content under the status bar upon app launch (it can be achieved now by scrolling).

This is my current result:

enter image description here

But I'd like it to appear like this:

enter image description here

I've set these attributes for the UINavigationController

enter image description here

And I've tried to adjust the insets like so in viewDidLoad:

[self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];

However, it doesn't display as desired.

Erik
  • 2,500
  • 6
  • 28
  • 49

3 Answers3

4

Add the code in this method- -viewDidLayoutSubview()

[self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
Vizllx
  • 9,135
  • 1
  • 41
  • 79
4

set the tableView contentInsetAdjustmentBehavior property

tableView.contentInsetAdjustmentBehavior = .never

Alaa Eddine Cherbib
  • 1,062
  • 14
  • 17
0

This is what worked for me.

tableView.contentInset = UIEdgeInsets(top: -UIApplication.shared.statusBarFrame.size.height, left: 0, bottom: 0, right: 0)
SivolcC
  • 3,258
  • 2
  • 14
  • 32
Steven Lee
  • 17
  • 2
  • 2
  • 6
  • 3
    Generally, answers are much more helpful if they include an explanation of what the code is intended to do, and why that solves the problem without introducing others. – SivolcC Feb 11 '19 at 05:13
  • When I click the status bar, the table view goes to zero content inset, which means it works but generates another problem.. – Yusuf Dec 27 '21 at 09:40