Empty white space above UITableView inside a UIVie

2019-01-22 02:08发布

I'm trying to position a TableView inside my ViewController view but leaving a 44 height gap between the bottom of the navigation bar and the top of the table. I then wanted to place a UITextField inside that gap to act as a stationary header. For some reason, the TableView has an empty white space above the start of the "Prototype Cells". Its just white space. Here is what it looks like in the storyboard.

storyboard

When viewing the app display, this is what it looks like:

app1

When scrolling the table, it goes all the way up to the correct place:

app2

7条回答
Ridiculous、
2楼-- · 2019-01-22 02:41

My issues is, I set tableHeaderView as new UIView like this

self.tableHeaderView = UIView(frame: .zero)

Remove this line, the issue is gone. Try this:

//self.tableHeaderView = UIView(frame: .zero)
查看更多
唯我独甜
3楼-- · 2019-01-22 02:42

You should not need to change the default setting for Extend Edges.

Looks like the real problem is a blank table header view in your storyboard. It's showing in the screenshot you provided of your storyboard, right below the Enter Name view and right above the Prototype Cells view. Delete it.

查看更多
beautiful°
4楼-- · 2019-01-22 02:44

Try this one:

self.tableView.contentInset = UIEdgeInsetsMake(-65, 0, 0, 0)
查看更多
我命由我不由天
5楼-- · 2019-01-22 02:52

I just found a solution for this. In my case, i was using TabBarViewController, A just uncheck the option 'Adjust Scroll View Insets'. Issues goes away.

https://i.stack.imgur.com/qgQI8.png

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-22 02:54

For Objective-C folks, add this in your ViewDidLoad method.

[self.tableView setContentInset:UIEdgeInsetsMake(-20, 0, 0, 0)];
查看更多
甜甜的少女心
7楼-- · 2019-01-22 02:55

Just add this in you ViewDidLoad method

self.automaticallyAdjustsScrollViewInsets = NO;
查看更多
登录 后发表回答