How to remove the blank space at the top of a grouped UITableView?

后端 未结 8 1144
南旧
南旧 2020-12-08 20:12

When you create a UITableView with the UITableViewStyleGrouped style, it adds quite a lot of space in between the actual tableviewcells and the bor

8条回答
  •  长情又很酷
    2020-12-08 21:00

    If the style of your tableView is UITableViewStyleGrouped, then you have to pay attention to the delegate of the height of SectionHeader or SectionFooter, cause this needs to be implemented right under this case.

    The return value should not be 0, even if the SectionHeader or the height of SectionFooter is 0, it needs to be a very small value; try CGFLOAT_MIN.

    For my example:

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == [self.dataArray indexOfObject:self.bannerList]) {
        return 46;
    }
    return CGFLOAT_MIN;
    

    }

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

    Make sure you implemented these two methods, and the value is right, and the top margin will be fixed.

提交回复
热议问题