删除UITableView中2节之间的标题空间

时间:2013-04-15 08:16:16

标签: iphone ios objective-c

我使用此代码为Table View Section Header设置颜色等

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    // create the parent view that will hold header Label
    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)];
    // create the button object
    UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.opaque = NO;
    headerLabel.textColor = [UIColor whiteColor];
    headerLabel.highlightedTextColor = [UIColor whiteColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:18];
    headerLabel.shadowColor = [UIColor blackColor];
    headerLabel.shadowOffset = CGSizeMake(0, 1.0);
    headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);

    if (section == 0) {

        headerLabel.text = @"Section 0 header";
        [customView addSubview:headerLabel];
    }
    if (section == 1) {

        //headerLabel.text = @"Section 1 header";
        //[customView addSubview:headerLabel];
        customView = nil;
        tableView.tableHeaderView = nil;
    }
    if (section == 2) {

        headerLabel.text = @"Section 2 header";
        [customView addSubview:headerLabel];
    }

    return customView;
}

在第1部分中,我不需要标题,但第0部分和第1部分之间仍有更大的空间。

enter image description here

1 个答案:

答案 0 :(得分:2)