ios 为什么 UITableView 顶部有额外的空间 - 简单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20305943/
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
why extra space is at top of UITableView - simple
提问by timpone
I'm picking up some iOS programming and am trying to put a UITableView into a storyboard. Unfortunately, I am trying to put the content at the top of the view but it is putting in some space. I have tried to adjust the values in the inspector for View -> Mode but this doesn't seem to have any effect.
我正在学习一些 iOS 编程,并试图将 UITableView 放入故事板中。不幸的是,我试图将内容放在视图的顶部,但它放入了一些空间。我试图在查看器中调整视图 -> 模式的值,但这似乎没有任何效果。
I have made the background green and put a border color to show the issue. I'm not a sophisticasted iOS dev, so I'd assume that this is the simplest solution and not something complex. How do I make the contents of the table view sit flush with the top? I've seen this Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7but not sure if it's related.
我已将背景设为绿色并添加边框颜色以显示问题。我不是一个老练的 iOS 开发人员,所以我认为这是最简单的解决方案,而不是复杂的东西。如何使表格视图的内容与顶部齐平?我已经看到这个为什么在我的 UITableView 顶部有额外的填充,在 iOS7 中使用 UITableViewStyleGrouped 样式,但不确定它是否相关。
thx for any help
感谢任何帮助
Edit #1
编辑 #1
Updated with changes and screen shot of properties for this table view
更新了此表视图的属性更改和屏幕截图
回答by Lyndsey Scott
Yes, that other question is very much related. UITableViewStyleGrouped
divides each section into a "group" by inserting that extra padding…similar to what it did pre-iOS7, but clear instead of colored by default, and just at the top instead of all the way around. If you don't want the padding by default, use UITableViewStylePlain
.
是的,另一个问题非常相关。UITableViewStyleGrouped
通过插入额外的填充将每个部分分成一个“组”......类似于它在 iOS7 之前所做的,但默认情况下是清晰的而不是彩色的,并且只是在顶部而不是所有的周围。如果您不希望默认填充,请使用UITableViewStylePlain
.
Otherwise, if you need to keep the style the same, do what this other posted from that link recommended and change the content inset:
否则,如果您需要保持样式不变,请执行从该链接推荐的其他帖子并更改内容插图:
self.tableView.contentInset = UIEdgeInsetsMake(-36, 0, 0, 0);
Or do what this poster suggested and set the tableHeaderView
's height
to .-1
, i.e. nearly 0
:
或者按照这张海报的建议进行操作并将tableHeaderView
's设置height
为.-1
,即几乎0
:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
回答by Muhammad_Awaab
Go to the attributes inspector of the View Controller by selecting the xib or the controller in Storyboard. Uncheck the Adjust Scroll View Insetsin Layout. It will solve the problem
通过在 Storyboard 中选择 xib 或控制器,转到视图控制器的属性检查器。取消选中Adjust Scroll View Insetsin Layout。它会解决问题
回答by Sir Wellington
Everybody keeps talking about this self.automaticallyAdjustsScrollViewInsets
option.
However this did not work for me at all. What did work for me, was setting the "Content Insets" property to Never
.
每个人都在谈论这个self.automaticallyAdjustsScrollViewInsets
选项。
然而,这对我根本不起作用。对我有用的是将“内容插入”属性设置为Never
.
Such an annoying problem.
这么烦人的问题。
回答by Rao
In Swift, you just need to set the below property to false.
在 Swift 中,您只需要将以下属性设置为 false。
self.automaticallyAdjustsScrollViewInsets = false
回答by Mohsin Qureshi
It is very easy and worked for me perfectly. Select a controller in Story Board in which you placed UITableView.
这很容易,对我来说非常有效。在 Story Board 中选择一个放置 UITableView 的控制器。
YouStoryboard.storyboard > YouViewController > Attributes inspector > Uncheck - Adjust scroll view insets.
YouStoryboard.storyboard > YouViewController > Attributes inspector > Uncheck - Adjust scroll view insets。
Make sure you select UIViewController not UITableView.
确保您选择 UIViewController 而不是 UITableView。
回答by AzSh
in swift 3.0, i hope will help you
在swift 3.0中,我希望能帮助你
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
回答by Saeed Ir
This is how it can be fixed easily through Storyboard:
这是它可以通过 Storyboard 轻松修复的方法:
Select Table View > Size Inspector > Content Insets: Never
选择表格视图 > 尺寸检查器 > 内容插入:从不
回答by A.G
Swift :
斯威夫特:
override func viewWillAppear(animated: Bool) {
self.edgesForExtendedLayout = UIRectEdge.None
OR
self.moduleListTableView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0);
OR
self.automaticallyAdjustsScrollViewInsets = false
}
回答by Ashwin Felix
try this....
尝试这个....
self.tableView.contentInset = UIEdgeInsetsMake( 20, 20 , 0, 0)
回答by Ashish Pisey
Cause of this issue:-
此问题的原因:-
- a UITableView doesn't like to have a header with a height of 0.0. If what's you're trying to do is to have a header with a height of 0, you can jump to the solution.
- even if later you assign a non 0.0 height to your header, a UITableView doesn't like to be assigned a header with a height of 0.0 at first.
- UITableView 不喜欢高度为 0.0 的标题。如果你想要做的是一个高度为 0 的标题,你可以跳到解决方案。
- 即使稍后您为标题分配了非 0.0 高度,UITableView 也不喜欢首先分配高度为 0.0 的标题。
In ViewDidLoad:-
在 ViewDidLoad 中:-
self.edgesForExtendedLayout = UIRectEdge.None
self.automaticallyAdjustsScrollViewInsets = false
No Need For Something Like This :-
不需要这样的东西:-
self.myTableview.contentInset = UIEdgeInsetsMake(-56, 0, 0, 0)
In heightForHeaderInSection
delegate:-
在heightForHeaderInSection
代表中:-
if section == 0
{
return 1
}
else
{
return 40; // your other headers height value
}
In viewForHeaderInSection
delegate :-
在viewForHeaderInSection
代表中:-
if section == 0
{
// Note CGFloat.min for swift
// For Objective-c CGFLOAT_MIN
let headerView = UIView.init(frame: CGRectMake(0.0, 0.0, self.myShaadiTableview.bounds.size.width, CGFloat.min))
return headerView
}
else
{
// Construct your other headers here
}