Search code examples
iosobjective-cstatusbar

Status bar blank


I'm working on UI design in iOS. When I try to add a subview into my root view, a blank appears under the status bar.

_tableViewController = [[TableViewController alloc] init];
_tableViewController.tableView.backgroundColor = [UIColor grayColor];
[self.view addSubview:_tableViewController.view];

blank

TableViewController is the class I define in other file.

But if I use UITableView instead, everything will be ok.

UITableView *tableView = [[UITableView alloc] init];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];

no blank

What's the reason for that?


Solution

  • The first line,

    _tableViewController = [[TableViewController alloc] init];
    

    That should be UITableViewController right?

    Also in simplistic terms a UITableViewController is a UITableView already in a UIViewController, so there shouldn't be a need to add it as a subview. This is why it respects the status bar and is full screen.

    The UITableView is just like any other view and doesn't respect such things. I hope this helps! It may be easier to use Storyboards if you are mainly doing UI work?