All the guidelines suggest adjusting the Top Layout Guide to avoid clobbering the status bar. But, if the page is created with a View Controller other than UIViewController (for example, if it is created with UITableViewController because the page is mainly a table view) then it has no layout guides. How can I then avoid the status bar?
-
1What is happening to the status bar? What do you mean that it is "getting clobbered" – SwiftMatt Dec 31 '15 at 23:40
-
The view overlaps it. – Mark Green Dec 31 '15 at 23:48
-
You can embed the UITableViewController in a UINavigationController. Refer to this [UITableView shows under status bar](https://stackoverflow.com/q/18900428/6521116) – LF00 Jan 15 '18 at 07:41
4 Answers
I've found the UITableViewController to be more trouble than it's worth, like this guy: How do I make my iOS7 UITableViewController NOT appear under the top status bar?
Now when I implement a table view I find it easier to make the TableView a property of the UIViewController, then you set the delegate and the datasource responsibilities to the UIViewController. From there you can customize it however you want really. You can play with the Storyboard options like the Status Bar setting (Inferred, None, Black etc) but in my experience I have found it works best by just putting a UITableView inside a UIViewController.
Example Header:
@interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
Example Code in Controller
@synthesize myTableView;
//**** Table View Delegate and Data Source ****//
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *myCellIdentifier = @"myCell";
MyTableViewCell *cell = (MyTableViewCell *)[myTableView dequeueReusableCellWithIdentifier:myCellIdentifier];
//Customize the cell
return cell;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return [myDataSource count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//perform some action on click
}
Another example of UITableViewController without a NavigationController and problems with the status bar: iOS 7: UITableView shows under status bar
-
Thanks. Annoying that Interface Builder allows you to set up combinations that are not supported and doesn't warn you. – Mark Green Jan 07 '16 at 00:56
An UITableViewController
(and all other standard view controllers) inherit from UIViewController
, so they have all the properties and methods of UIViewController
, including top and bottom layout guides, which you can definitely use.

- 17,302
- 6
- 32
- 46
-
How do you make the top and bottom layout guides for a UITableViewController appear in the XCode Interface Designer? – Mark Green Jan 05 '16 at 23:50
-
As far as I know, in Interface Builder, you cannot add any views to a Table View Controller which are not either table view headers or footers, cells, or subviews of a cell's content view, so there wouldn't be much point adding constraints to the top layout guide for any of those. If you have issues with your table view's contents underlapping the status bar, it doesn't really like not being embedded in a navigation controller... – jcaron Jan 06 '16 at 02:06
Since UITableViewController is inherited from UIViewController, then in Tableviewcontroller, you can override this method
- (UIStatusBarStyle)preferredStatusBarStyle {
if(<#condition>)
{
return UIStatusBarStyleLightContent;
}
else
{
return UIStatusBarStyleDefault;
}
}

- 4,739
- 1
- 19
- 35
If you must use UITableViewController you can embed it inside a UIViewController with an Embed Segue and do whatever you want in the UIViewController

- 4,820
- 2
- 30
- 36