xcode 他们是否在 iOS 11 中向 UITableVIew 添加了更多填充?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46339344/
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
Did they add more padding to UITableVIew in iOS 11?
提问by Phillip
Is it just me or they added a lot more padding to section headers and footers of grouped UITableView
s in iOS 11?
是我还是他们UITableView
在 iOS 11 中为 grouped s 的部分页眉和页脚添加了更多填充?
I compiled my app to run with iOS 11 and noticed the extra padding.
I kinda solved it by setting contentInset.top
to a negative value checking if the os is iOS 11, but this is a ugly workaround.
我编译了我的应用程序以在 iOS 11 上运行并注意到额外的填充。我有点通过设置contentInset.top
为负值来检查操作系统是否为 iOS 11 来解决它,但这是一个丑陋的解决方法。
Is there any other better way do clear the extra padding of grouped table views in order to achieve the same results across all supported iOS? It kinda stinks to have multiple checks for such a silly thing.
有没有其他更好的方法可以清除分组表视图的额外填充,以便在所有受支持的 iOS 上获得相同的结果?对这种愚蠢的事情进行多次检查有点糟糕。
Screenshot for comparison:
截图对比:
As you can see, on iOS 11 there's extra spacing between sections (yeah, those are sections!).
如您所见,在 iOS 11 上,部分之间有额外的间距(是的,那些是部分!)。
回答by Rashid
This is new contentInsetAdjustmentBehavior parameter of UIScrollView which you can set it as .never to prevent extra padding
这是 UIScrollView 的新 contentInsetAdjustmentBehavior 参数,您可以将其设置为 .never 以防止额外填充
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
}
or in storyboard under Size Inspector
或在大小检查器下的故事板中
回答by Bms270
In iOS 11 the section footer has a view that adds to the spacing between the sections. You would need to set the view of the footer to nil explicitly in addition to adjusting the height for the footer:
在 iOS 11 中,节页脚有一个视图,可以增加节之间的间距。除了调整页脚的高度外,您还需要将页脚的视图显式设置为 nil:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}
This will make your table view to look like what you had in iOS 10 and would also not have any effect on previous versions of iOS. You can do the same for the header if you don't need the headers.
这将使您的 table view 看起来像您在 iOS 10 中的样子,并且不会对以前版本的 iOS 产生任何影响。如果您不需要标题,您可以对标题执行相同的操作。
回答by wangjx
You just need to set the table view's header and footer view.
您只需要设置表格视图的页眉和页脚视图。
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] init];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] init];
}
回答by HannahCarney
I had a similar problem I think it was a bug in the Old Xcode.
我有一个类似的问题,我认为这是旧 Xcode 中的一个错误。
If you are using autolayout and you have Content View and views inside this, Constrain to margins didn't work in Xcode 8, now fixed in xCode 9. You have to go in redo your constraints and uncheck the box on the View inside all table view cells. This will then be consistent on all ios 10 and ios 11 devices.
如果您正在使用自动布局并且您在其中有内容视图和视图,则约束到边距在 Xcode 8 中不起作用,现在已在 xCode 9 中修复。您必须重做约束并取消选中所有表内视图上的框查看单元格。这将在所有 ios 10 和 ios 11 设备上保持一致。
回答by ?or?e Nilovi?
I solved my problem by setting the header and footer height in Storyboard. Apparently, in Xcode 9 these are the default values when you create a UITableView
我通过在 Storyboard 中设置页眉和页脚高度解决了我的问题。显然,在 Xcode 9 中,这些是创建 UITableView 时的默认值
I tried to set them to 0, but 1 is the minimum and that solved the problem. Also, I checked how it behaves if the automaticis checked and it works as well.
我试图将它们设置为 0,但 1 是最小值并且解决了问题。另外,我检查了如果自动被选中并且它也能正常工作,它的行为方式。
Also, I don't know is it a bug or something, but I couldn't do it on existing table. I needed to delete it and drag it to UIViewController again.
另外,我不知道这是错误还是什么,但我无法在现有表上执行此操作。我需要删除它并再次将其拖到 UIViewController 中。
回答by Luca Ventura
If rashid's answer didn't work with setting the contentInsetAdjustmentBehavior to never then try the following:
如果拉希德的回答在将 contentInsetAdjustmentBehavior 设置为 never 时不起作用,请尝试以下操作:
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0
self.tableView.estimatedSectionFooterHeight = 0
回答by AamirR
With my .grouped
UITableView I was facing the same issue in iOS 11, it worked fine when I was using a UITableViewController
, but not in UIViewController
, following worked in my case:
对于我的.grouped
UITableView,我在 iOS 11 中遇到了同样的问题,当我使用 a 时它工作正常UITableViewController
,但不是UIViewController
在我的情况下工作:
tableView.estimatedSectionHeaderHeight = 0
Without above line tableView(heightForHeaderInSection
never gets called.
没有上面的线tableView(heightForHeaderInSection
永远不会被调用。
It seems like a bug in iOS 11.
这似乎是 iOS 11 中的一个错误。