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.
You also have to implement tableView:heightForHeaderInSection:
on your table view delegate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With