Space Between Sections in UITableview

2019-01-22 17:32发布

I need to reduce the space between two sections ofUITableView. I looked at this question but the solution doesn't allow for my custom header view because it combines the space of the footer and header.

Here is a picture of the UITableView. The black color is the UITableView background color.

tableview screenshot

8条回答
Root(大扎)
2楼-- · 2019-01-22 18:10

Did you try override this function:

 override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 0.00001
  }
查看更多
老娘就宠你
3楼-- · 2019-01-22 18:11

This also may help :

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.sectionHeaderHeight = UITableViewAutomaticDimension
}
查看更多
劫难
4楼-- · 2019-01-22 18:15

Along with the answer posted by Icaro I would like to add that you also need to implement the tableView:viewForFooterInSection: method returning nil for the section you want to remove the empty space below It will then become:

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001f;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return nil;
}
查看更多
萌系小妹纸
5楼-- · 2019-01-22 18:18

TableView Delegate methods doesn't effect with float value is 0.0f. Try giving a value greater than that.

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.00001f;
}

- (UIView*)tableView:(UITableView*)tableView
viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}
查看更多
你好瞎i
6楼-- · 2019-01-22 18:20

I think you can solve this by adjusting the footer view height to its min: in Storyboard or XIB.enter image description here

I don't know what you have written in your code for footer height. Sorry if I am wrong.

Possible duplicate of Hide footer view in UITableView

查看更多
虎瘦雄心在
7楼-- · 2019-01-22 18:22

For Swift 3

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return CGFloat.leastNormalMagnitude
}
查看更多
登录 后发表回答