2012-11-01 65 views
1

可能重複:
Reducing the space between sections of the UITableViewUITableView部分之間的iOS空間不受控制?

進出口使用的組合風格UITableView,我想,以減少sections.I've之間的間距嘗試這些:

- (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; 
} 

但我部分之間會有更多的空間。 我錯過了什麼?

+0

看一看這樣的:http://stackoverflow.com/questions/2817308/reducing-the-space-between -sections-of-the-uitableview – lakesh

回答

4

只要看看周圍的代碼,我已經更換了一些行代碼:

- (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]; 
} 
+0

謝謝Amit,它正在尋找什麼。 – Blios