iOS 7 UITableView:如何删除导航栏和第一个单元格之间的空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19111451/
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
iOS 7 UITableView: How to remove space between navigation bar and first cell
提问by Fry
my problem is: with iOS 7 in grouped UITableView
there is a gap from the top of the table and the first cell.
我的问题是:将 iOS 7 分组UITableView
后,表格顶部和第一个单元格之间存在间隙。
The strange is that when I load the content for the first time the table appears ok like in the first image, but when I scroll down a space appears between top and first cell like in the second:
奇怪的是,当我第一次加载内容时,表格在第一张图像中看起来还可以,但是当我向下滚动时,顶部和第一个单元格之间会出现一个空格,如第二张:
With style plain this behavior does't came out but unfortunately I need to use grouped table view.
使用简单的样式,这种行为不会出现,但不幸的是我需要使用分组表视图。
Any ideas about ?
任何想法?
回答by Slavcho
Just add this in you ViewDidLoad
method
只需在你的ViewDidLoad
方法中添加这个
self.automaticallyAdjustsScrollViewInsets = NO;
回答by Giorgos Ath
The answer was very funny for me and my team, and worked like a charm
答案对我和我的团队来说非常有趣,而且效果很好
- In the Interface Builder, Just move the tableview under another view in the view hierarchy.
- 在 Interface Builder 中,只需将 tableview 移动到视图层次结构中的另一个视图下。
REASON:
原因:
We observed that this happens only for the First View in the View Hierarchy, if this first view is a UITableView. So, all other similar UITableViews do not have this annoying section, except the first. We Tried moving the UITableView out of the first place in the view hierarchy, and everything was working as expected.
我们观察到这种情况只发生在视图层次结构中的第一个视图中,如果第一个视图是 UITableView。所以,除了第一个之外,所有其他类似的 UITableViews 都没有这个烦人的部分。我们尝试将 UITableView 从视图层次结构中的第一个位置移出,一切都按预期工作。
回答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 clmntcrl
If you are using a UITableView with grouped style and only 1 group, use plain style instead solve your problem.
如果您使用的是带有分组样式且只有 1 个组的 UITableView,请使用普通样式来解决您的问题。
UITableViewController *tableViewController;
tableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
回答by Venu Gopal Tewari
Simplest solution to this problem in grouped type tableView
is:
分组类型中此问题的最简单解决方案tableView
是:
tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
回答by Daniel Beltrami
For solve this problem make sure that you unchecked this field on ViewController:
要解决此问题,请确保在 ViewController 上取消选中此字段:
On ViewController >> Attibutes Inspector >> Layout (unchecked - Adjust Scroll View Insets)
在 ViewController >> Attibutes Inspector >> Layout (未选中 -调整滚动视图插入)
if this is not enough, try this on TableView, set Style to Plain:
如果这还不够,请在 TableView 上尝试此操作,将 Style 设置为Plain:
This will solve your problem
这将解决您的问题
回答by Hot'n'Young
guys! I had the same problem. TableView appeared with free space between nav bar and first cell. This code saved me:
伙计们!我有同样的问题。TableView 出现在导航栏和第一个单元格之间的可用空间。这段代码救了我:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return 10;
}
else return 2;
}
回答by IPL10
I am working with Xcode 7.3.1
, iOS9
, and swift 2
. I would like to share what worked for me:
我有工作Xcode 7.3.1
,iOS9
和swift 2
。我想分享对我有用的东西:
Just add this in you ViewDidLoad
method
只需在你的ViewDidLoad
方法中添加这个
self.automaticallyAdjustsScrollViewInsets = false;
回答by love2script12
There was a space above the UITableView itself, and also between the cells. Found my solution in 2 different answers above..posting it again so that nobody misses both solutions.
UITableView 本身上方有一个空间,单元格之间也有一个空间。在上面的 2 个不同答案中找到了我的解决方案..再次发布它,以便没有人错过这两个解决方案。
This removed the space from above :
这从上面删除了空间:
self.automaticallyAdjustsScrollViewInsets = NO;
and this removed the spaces below the cells : Setting the 'Style' attribute of the UITableView to 'Plain'
这删除了单元格下方的空格:将 UITableView 的 'Style' 属性设置为 'Plain'
回答by Adam Johns
I was seeing this extra space at the top of one of my table views in a very strange situation.
我在一个非常奇怪的情况下在我的一个表格视图的顶部看到了这个额外的空间。
After I added a UIScrollView
as the root view of my first controller in my navigation stack, if I presented the next controller as a Show Detail
segue, my next controller would have the space above its table view.
UIScrollView
在我的导航堆栈中添加一个作为我的第一个控制器的根视图后,如果我将下一个控制器呈现为Show Detail
segue,我的下一个控制器将在其表视图上方有空间。
The solution for me was to change the segue to Present Modally
and everything went back to normal.
我的解决方案是将 segue 更改为Present Modally
,一切都恢复正常。
The strangest part of the segue changing was that beforeI added my root view being a UIScrollView
, my Show Detail
segue was presenting the next controller modally. Yet afterI added the root UIScrollView
, the Show Detail
segue was pushingon the next controller (which was not what I wanted).
segue 更改中最奇怪的部分是,在我将根视图添加为 a 之前UIScrollView
,我的Show Detail
segue 以模态方式呈现下一个控制器。然而,在我添加 root 之后UIScrollView
,Show Detail
segue 正在推动下一个控制器(这不是我想要的)。