My tableview has an extra space at the bottom, as you see in the picture:
All the rows in the tableView have a fixed height of 71pt.
in this case you can give tableview the bottom space 0 to its superview and it will work i think or you can do,
tableView.tableFooterView = UIView();
or you can do like below,
The lower value should be 1.0.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )section {
if(section == 0) {
return 6;
} else {
return 1.0;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger )section {
return 5.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger )section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}
@urgentx's answer did most of what I wanted but didn't get all the way there. I'm in a similar situation (upside down UITableView for a chat app) however their suggestion fully disables safe area behavior which isn't desirable on devices like the iPhone X because it means the tableview will be clipped by both the home indicator and any top navigation bars.
I did the following in order to make the tableview still correctly avoid safe areas while inverted:
override func viewDidLoad() {
super.viewDidLoad()
self.automaticallyAdjustsScrollViewInsets = false
self.tableView.contentInsetAdjustmentBehavior = .never
}
and then:
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
//fetch the safe area in layoutSubviews since this it's possible that they can change when the device is rotated
let safeArea = self.tableView.safeAreaInsets
//insets are **flipped** because the tableview is flipped over its Y-axis!
self.tableView.contentInset = .init(top: safeArea.bottom, left: 0, bottom: safeArea.top, right: 0)
}
This in essence replicates contentInsetAdjustmentBehavior = .automatic
behavior but with the insets flipped across the Y-axis.
The accepted solution is no longer a correct one if it comes to iOS 11 and Xcode 9. To achieve similar effect you have to go to Size Inspector where you can find this:
You can achieve the same in code:
if #available(iOS 11.0, *) {
scrollView.contentInsetAdjustmentBehavior = .never
} else {
automaticallyAdjustsScrollViewInsets = false
}
I had this issue when I flipped my UITableView upside-down for a chat messaging screen.
Before I flipped the table view, the content inset was leaving a blank space at the top so that when we scrolled all the way up, the content was not obstructed by the navigation bar. Once I flipped it the inset was moved to the bottom.
Change your 'Content Insets' to Never in the Size Inspector of your UITableView to get rid of this space at the end.
Ok, I got it.
The "Adjust Scroll View Insets" was marked on my viewController (not my tableView).
Here is an answer with a detailed explanation