【问题标题】:Status bar blank状态栏空白
【发布时间】:2026-01-01 01:50:01
【问题描述】:

我正在 iOS 中进行 UI 设计。当我尝试将子视图添加到我的根视图中时,状态栏下方会出现一个空白。

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

TableViewController 是我在其他文件中定义的类。

但如果我改用UITableView,一切都会好起来的。

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

这是什么原因?

【问题讨论】:

    标签: ios objective-c statusbar


    【解决方案1】:

    第一行,

    _tableViewController = [[TableViewController alloc] init];
    

    应该是 UITableViewController 吧?

    同样简单来说,UITableViewController 是 UIViewController 中的 UITableView,因此不需要将其添加为子视图。这就是为什么它尊重状态栏并且是全屏的。

    UITableView 就像任何其他视图一样,不尊重这些东西。我希望这有帮助!如果您主要从事 UI 工作,使用 Storyboard 可能会更容易?

    【讨论】: