Search code examples
iphonexcodeuitableviewios5grouped-table

sectionName TableView - What am I doing wrong?


I'm having some trouble changing the colour and font on a TableView that I have split into 4 sections with names etc., I can;t seem to get it to work I'm not sure what I am doing wrong?

- (NSString *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section     {

NSString *sectionName = nil;

switch(section)
{
    case 0:
        sectionName = [NSString stringWithString:@"Date"];
        break;
    case 1:
        sectionName = [NSString stringWithString:@"Gig"];
        break;
    case 2:
        sectionName = [NSString stringWithString:@"City"];
        break;
    case 3:
        sectionName = [NSString stringWithString:@"Country"];
        break;
}

UILabel *sectionHeader = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)]   autorelease];
sectionHeader.backgroundColor = [UIColor clearColor];
sectionHeader.font = [UIFont boldSystemFontOfSize:18];
sectionHeader.textColor = [UIColor whiteColor];
sectionHeader.text = sectionName;

return sectionName;
}

Solution

  • you should return the view instead of the string...

    This is what you are returning

    return sectionName;
    

    And this is what you should return..

    return sectionHeader;