ios UIView 中 UITableView 上方的空白区域
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27827315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Empty white space above UITableView inside a UIView
提问by Fenda
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.
我试图在我的 ViewController 视图中放置一个 TableView,但在导航栏底部和表格顶部之间留下 44 的高度间隙。然后我想在该间隙内放置一个 UITextField 作为固定标题。出于某种原因,TableView 在“原型单元格”的开头上方有一个空白区域。它只是空白。这是故事板中的样子。
When viewing the app display, this is what it looks like:
查看应用程序显示时,它是这样的:
When scrolling the table, it goes all the way up to the correct place:
滚动表格时,它会一直移动到正确的位置:
回答by oren
Try to look in the 'attribute inspector' (in the right menu) of the Participants ViewController. Check for the option 'Extend Edges'and uncheck the 'Under Top Bars', and then relocate your tableview.
尝试查看参与者 ViewController 的“属性检查器”(在右侧菜单中)。选中“扩展边缘”选项并取消选中“顶栏下方”,然后重新定位您的表格视图。
Another possible solution is to just uncheck the option 'Adjust Scroll View Insets'. The reason is that when the viewController extends its edges, let's say under the top bar, the tableView's scrollView automatically adjusts its inset top, so that the content of the tableView will start exactly under the top bar. But in your case this is not needed, since your tableView itself starts under the bar.
另一种可能的解决方案是取消选中“调整滚动视图插入”选项。原因是当 viewController 扩展其边缘时,假设在顶部栏下方,tableView 的 scrollView 会自动调整其插入顶部,以便 tableView 的内容将正好在顶部栏下方开始。但在您的情况下,这不是必需的,因为您的 tableView 本身在栏下开始。
Focus on the ViewController and got to the Attribute Inspector tab:
关注 ViewController 并进入 Attribute Inspector 选项卡:
回答by Natividad Lara Diaz
Try this one:
试试这个:
self.tableView.contentInset = UIEdgeInsetsMake(-65, 0, 0, 0)
回答by Fadi Abuzant
Just add this in you ViewDidLoad method
只需在您的 ViewDidLoad 方法中添加它
self.automaticallyAdjustsScrollViewInsets = NO;
回答by Mike Taverne
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.
看起来真正的问题是故事板中的空白表格标题视图。它显示在您提供的故事板屏幕截图中,位于 Enter Name 视图的正下方和 Prototype Cells 视图的正上方。删除它。
回答by AshvinGudaliya
My issues is, I set tableHeaderView
as new UIView
like this
我的问题是,我像这样设置tableHeaderView
为新的UIView
self.tableHeaderView = UIView(frame: .zero)
Remove this line, the issue is gone. Try this:
去掉这一行,问题就解决了。尝试这个:
//self.tableHeaderView = UIView(frame: .zero)
回答by NitinLandge
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.
我刚刚找到了解决方案。就我而言,我使用的是 TabBarViewController,只需取消选中“调整滚动视图插入”选项即可。问题消失了。
回答by Rishabh Munde
For Objective-C folks, add this in your ViewDidLoad method.
对于 Objective-C 的人,请将其添加到您的 ViewDidLoad 方法中。
[self.tableView setContentInset:UIEdgeInsetsMake(-20, 0, 0, 0)];