问题
I am using both UITableViewController
and UITableView
in one project.
An UITableView
in an UITableViewController
overlays the home indicator on iPhone X.
But an UITableView
in an UIViewController
doesn't overlay the home indicator on iPhone X.
Should I fit one?
And which one is correct when I consider about safe area?
e.x.


回答1:
You can continue to use a UITableView
on a standard UIViewController
. Just set auto layout so the bottom of the tableview is flush with the bottom of the superview (and not the margin). Then set the insetsContentViewsToSafeArea
property of the tableview to true
Swift:
if #available(iOS 11.0, *) {
tableView.insetsContentViewsToSafeArea = true;
}
Objective-C:
if (@available(iOS 11.0, *)) {
[tableView setInsetsContentViewsToSafeArea:YES];
}
回答2:
This is what worked for me, in iOS 12:
I tried setting insetsContentViewsToSafeArea
but that didn't work, although it set me on the right path. What fixed it for me was setting the "Content Insets" in the nib/storyboard to "Never" (in the code, that property is contentInsetAdjustmentBehavior
).
Explanation: It seems that, for iPhoneX and above, the system automatically adds some bottom padding for table views so that the content goes above the home indicator.
回答3:
This is because table view in UITableViewController is root view. It will extend to full screen. But you can make constraints to bottom layout guide for table view in UIViewController. So you can use UIViewController. Or you can set content insets in UITableViewController.
来源:https://stackoverflow.com/questions/46924041/tableview-and-the-home-indicator-on-iphone-x