views:

44

answers:

2

I need to place a button immediately above a dynamically populated UIViewTable. It feels right to not populate the first cell (row 0), but rather utilize the header area, so I use the UITableViewDelegate method to programmatically create a UIView containing a UIButton:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{        
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 44)] autorelease]; // x,y,width,height

    UIButton *reportButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];    
    reportButton.frame = CGRectMake(80.0, 0, 160.0, 40.0); // x,y,width,height
    [reportButton setTitle:@"rep" forState:UIControlStateNormal];
    [reportButton addTarget:self 
                     action:@selector(buttonPressed:)
           forControlEvents:UIControlEventTouchDown];        

    [headerView addSubview:reportButton];
    return headerView;    
}

However, as depicted below, the button is not given the necessary space (I expected the height of the header to adhere to the 44 argument).

What is wrong here? I should add that the UITableView is created in a separate XIB-file.

alt text

+1  A: 

You also have to implement tableView:heightForHeaderInSection: on your table view delegate.

Robot K
No that was it. Thanks.
maralbjo
+1  A: 

did you implement - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section?

fluchtpunkt
Too bad I can only reward one answer. Thanks.
maralbjo