顶部的"UITableView"额外空间

Mor*_*lde 3 uitableview ios swift

我不记得在UITableView为场景添加s 时看到这个额外的空间.当我从Interface Builder中的对象库中拖动默认对象时,就会发生这种情况.

为了突出差距,我将表格的背景颜色更改为灰色.

在此输入图像描述

我用以下代码填充表中的数据.

extension UserListViewController: UITableViewDataSource {
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return users.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .Subtitle, reuseIdentifier: nil)
        cell.textLabel?.text = users[indexPath.row].name
        return cell
    }
}
Run Code Online (Sandbox Code Playgroud)

dataSourceviewDidLoad在视图控制器的内部设置了轮廓.

tableView.dataSource = self
Run Code Online (Sandbox Code Playgroud)

那么这个差距来自哪里呢?我怎么摆脱它呢?

nic*_*525 13

您也可以直接从StoryBoard中的UIViewController的属性检查器中取消选择它,这样就不会添加代码.

在此输入图像描述


str*_*eem 5

您可以尝试在控制器中设置它:

self.automaticallyAdjustsScrollViewInsets = false
Run Code Online (Sandbox Code Playgroud)

这个属性非常自我解释.在iOS 7中,Apple推出了半透明顶杆.通常他们希望您的UITableview从顶部开始,就像顶部栏后面的某些部分一样.在这种情况下,在顶部具有自动插入以使内容可见是有用的.