views:

29

answers:

1

I'm having trouble changing the section header for my grouped uitableview. I have tried everything. I have wondered whether it is a bug with the simulator or something? I am running the latest version of xcode and am developing for the iPad.

Here's my tableview header code

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

    UILabel *label = [[[UILabel alloc] init] autorelease];
    label.frame = CGRectMake(20, 6, 300, 30);
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.shadowColor = [UIColor grayColor];
    label.shadowOffset = CGSizeMake(0.0, 1.0);
    label.font = [UIFont boldSystemFontOfSize:14];
    label.text = @"hello"; //sectionHeader;

    return label;

}

When I compile, it simply displays with NO headings. I've also tried to add a view here too, as per the code below

UIView *sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
sectionView.backgroundColor = [UIColor redColor];
[sectionView autorelease];
[sectionView addSubview:label];
return sectionView;

Am I doing something wrong?

+1  A: 

From the documentation:

[tableView:viewForHeaderInSection:] only works correctly when tableView:heightForHeaderInSection: is also implemented.

Ed Marty
sorry - I do have that there too... I have set the height to 50.0
Matt Facer
Have you confirmed that the code is, in fact, being run? If not, put a break point or NSLog in there to make sure it's actually being used. If not, make sure the table view's delegate is set to be the object you're using. Not just the data source. The method for getting a section's title is in the datasource protocol, but the method for returning the section's title as a view is in the delegate protocol.
Ed Marty
perfect, thank you. As you said, I'd not set the table view's delegate. Many thanks!
Matt Facer