I have a UITableView that is styled as a grouped tableView. Under certain circumstances I need to create a custom view for the header and under other circumstances I want the default one.
Creating a custom header is the easy part - simply use the delegate:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
However, what do I return from this delegate if I want the default header view instead?
I've tried returning nil and this only works as expected when the table view is styled as Plain. If the table view is styled as Grouped then the default header disappears when I return nil.
How do I get the default header back taking into account that I need to sometimes have custom header views too?
Edit:
I think I've found the problem. In tableView:heightForHeaderInSection: I do the following:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if ([myArray count] == 0) return 80;
else return [tableView sectionHeaderHeight];
}
It seems that [tableView sectionHeaderHeight] returns an incorrect height for my header. It sets it to 10 but it should be about 30.
If you need to make the footer view fixed at the bottom then you can not use a TableViewController . You will have to use UIViewController , put your tableView as a subview. Put the footer also as another subview and its done.
The correct answer to the above questions is:
To return the default view return nil
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return nil;
}
To return the default header height return -1
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return -1;
}
That worked for me !
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