Ios – TableView titleForHeaderInSection

iosiphoneobjective c

My app shows this in the 4.3.1 simulator                   and this in the 5.0 simulator.

4.3.1 simulator5.0 simulator

This is the code:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
   return @""; 
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[Singleton sharedInstance] getTitleSectionView:segmentedControl.selectedSegmentIndex inDay:section];
}
-(UIView *)getTitleSectionView:(int)week inDay:(int)day;
{
UILabel *lab=[[[UILabel alloc]init]autorelease];
lab.frame=CGRectMake(5, 0,320,20);
lab.text=[[Singleton sharedInstance] getTitleSection:week inDay:day];
lab.backgroundColor=[UIColor clearColor];
lab.textColor=[UIColor whiteColor];
lab.font = [UIFont fontWithName:@"Arial" size:14];

UIImageView * imv = [[[UIImageView alloc]initWithFrame:CGRectMake(0,0, 320, 20)]autorelease];
imv.image=[UIImage imageNamed:@"section-header-bg.png"];

UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)]autorelease];
[view addSubview:imv];
[view addSubview:lab];

    Week *currentWeek = nil;
    if(week)    
        currentWeek = nechetNedel;
    else        
        currentWeek = chetNedel;

    NSMutableArray *dayArray = [currentWeek.days objectAtIndex:day];
    if([dayArray count] >0)
        return view;
    return nil;
}

What can be the problem, why does lines of sections appear in the 5.0 simulator? I tried to delete the method - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section but it did not help. I delete this method(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section and the lines disappear

Best Answer

You should return nil for empty sections

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

and

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

should return 0

Then it will work. It is iOS 5.x issue (or feature)

Related Topic