1

Possible Duplicate:
Reducing the space between sections of the UITableView

Im usingUITableView of grouped style and i want to reduce spacing between sections.I've tried these:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 32)];

    UIImageView* headerbg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top_bg.png"]];
    headerbg.frame = CGRectMake(8.0, 0.0, 302.0, 44.0);
    [customView addSubview:headerbg];

    UILabel * headerLabel = [[FontLabel alloc] initWithFrame:CGRectZero fontName:@"HelveticaNeue-Medium"
                                               pointSize:16.0f];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.opaque = NO;
    headerLabel.textColor = [UIColor colorWithRed:17.0/255.0 green:117.0/255.0 blue:1.0/255.0 alpha:1.0];
    headerLabel.frame = CGRectMake(10, 10.0, 300.0, 30);
    headerLabel.text = @"Reserve";

    [headerbg addSubview:headerLabel];

    if(section == 1 || section == 2)
    {
        headerbg.image = nil;
        headerLabel.text = nil;
        return nil;
    }
    return customView;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

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

        return 25;
    }
    else
        return 0;

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

    return 0;
}

But i'm getting more space between sections. What am i missing?

Community
  • 1
  • 1
Blios
  • 719
  • 1
  • 16
  • 30
  • Have a look at this: http://stackoverflow.com/questions/2817308/reducing-the-space-between-sections-of-the-uitableview – lakshmen Nov 01 '12 at 12:48

1 Answers1

4

Just look around the code, i have replaced some line in your code :

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0) 
    return 25;
else
    return 1;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
 UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 32)];

UIImageView* headerbg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top_bg.png"]];
headerbg.frame = CGRectMake(8.0, 0.0, 302.0, 44.0);
[customView addSubview:headerbg];

UILabel * headerLabel = [[FontLabel alloc] initWithFrame:CGRectZero fontName:@"HelveticaNeue-Medium"
                                           pointSize:16.0f];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor colorWithRed:17.0/255.0 green:117.0/255.0 blue:1.0/255.0 alpha:1.0];
headerLabel.frame = CGRectMake(10, 10.0, 300.0, 30);
headerLabel.text = @"Reserve";

[headerbg addSubview:headerLabel];

if(section == 1 || section == 2)
{
    headerbg.image = nil;
    headerLabel.text = nil;
    return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}
return customView;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}
Amit Singh
  • 428
  • 3
  • 10