分组表视图顶部空白高度怎么调整

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }else
        return 30;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }else
        return 30;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return nil;
    }else {
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 30)];
        headerView.backgroundColor = [UIColor whiteColor];

        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 30)];
        [label setText:@"    药品名称       单价         数量     总价   "];
        [headerView addSubview:label];
        return headerView;
    }
}

请输入图片描述
如图和代码,在section0的上面一段空缺灰色的,不知道怎么调整其高度。

阅读 11.2k
2 个回答
新手上路,请多包涵
 UIEdgeInsets contentInset = tableView.contentInset;
 contentInset.top = 0;
 [tableView setContentInset:contentInset];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题