在状态栏下显示tableView

3

我想在应用启动时将UITableView的内容显示在状态栏下方(现在可以通过滚动实现)。

这是我的当前结果:

enter image description here

但我希望它显示为这样:

enter image description here

我已经为UINavigationController设置了这些属性。

enter image description here

我尝试在viewDidLoad中调整插图,如下所示:

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

然而,它并没有按预期显示。

你是通过代码创建TableView还是拖拽到Storyboard中? - Saheb Roy
@SahebRoy 这是一个由 UITableViewController 创建的故事板。 - Erik
使用一个UIViewController子类并使用一个TableView怎么样? 或者您可以取消勾选“在顶部栏下方”扩展边缘,然后检查结果。 - Saheb Roy
3个回答

5

设置tableView的contentInsetAdjustmentBehavior属性

tableView.contentInsetAdjustmentBehavior = .never


4
在这个方法中添加代码- -viewDidLayoutSubview()
[self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];

1
更简单的语法:self.tableView.contentInset = UIEdgeInsetsZero; - gklka

0

这是对我有效的方法。

tableView.contentInset = UIEdgeInsets(top: -UIApplication.shared.statusBarFrame.size.height, left: 0, bottom: 0, right: 0)

3
通常,如果答案包括代码意图和解释,说明它解决了问题且不会引入其他问题,那么答案会更有帮助。 - SivolcC
当我点击状态栏时,表视图会变为零内容插入,这意味着它可以工作,但会产生另一个问题。 - Yusuf

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接