Grouped table views seem to have extra padding on the bottom in iOS 6 (iOS 5 does not have it), but I can\'t find any documentation that suggests this is correct / expected
Swift 3 code
class PaddingLessTableView : UITableView
{
override func layoutSubviews() {
self.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
super.layoutSubviews()
}
}
this solves the issue:
Obj-c
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.1;
}
Swift:
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.1
}
This is the only working solution I guess.I tried setting tableFooterView
and tableHeaderView
to nil
.
But nothing happened.Then the following solution worked .Returning zero "return 0;" has no effect.We should return the lowest possible height.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
NOTE: This is what I got when printed the values.
CGFLOAT_MAX = 340282346638528859811704183484516925440.000000
CGFLOAT_MIN = 0.000000
In Swift 4.2 you can try setting table header with least normal magnitude height -
var frame = CGRect.zero
frame.size.height = .leastNormalMagnitude
tableView.tableHeaderView = UIView(frame: frame)
@frankWhite' solution works great, but here is a better solution to avoid typing 0.1, 0.001 or others to make it less ambiguous.
// Swift version
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
// remove bottom extra 20px space.
return CGFloat.min
}
// Objective-C version
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
// remove bottom extra 20px space.
return CGFLOAT_MIN;
}
in Swift 3
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}