Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom header overlaps cells in group

Im a bit stuck trying to create a custom ios table header. My headers are 30px tall and I am using this code to create them:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
    if (sectionTitle == nil) {
        return nil;
    }

    // Create label with section title
    UILabel *label = [[UILabel alloc] init] ;
    label.frame = CGRectMake(0, 0, 140, 30);
    label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"header_gradient.png"]];
    label.textColor = [UIColor whiteColor];
    label.shadowColor = [UIColor whiteColor];
    label.shadowOffset = CGSizeMake(0.0, 1.0);
    label.font = [UIFont boldSystemFontOfSize:12];
    label.text = sectionTitle;

    // Create header view and add label as a subview
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 140, 30)];
    [view addSubview:label];

    return view;
}

- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section {
    return 30;
} 

It almost works, but my headers seem to colide with the cells/headers below them:

custom headers

Can anyone point me in the right direction on cleaning up the headers here?

Thanks in advance

like image 526
akhalsa Avatar asked Apr 28 '12 00:04

akhalsa


1 Answers

You're missing a [space]:

You have:

- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section {

It should be:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
like image 102
Kerri Shotts Avatar answered Nov 10 '22 18:11

Kerri Shotts