Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically remove the header of UITableView and automatically resizes the content to fill in the removed area

I have added a UIButton in the header section of the UITableView via the interface builder and would like to remove the access to the button in certain cases. I have tried to use the .hidden = TRUE property but it just hides the button from the view, leaving a white space behind. How do I programmatically remove the header of UITableView and have the table's content automatically resizes to fill in the removed header area?

like image 373
code007 Avatar asked Mar 02 '11 06:03

code007


2 Answers

If you want to remove the table's header view, just set the myTable.tableHeaderView property to nil. If what you have is actually a section header, then you need to return nil from the viewForHeaderInSection method and call [myTableView reloadData]

like image 149
Bogatyr Avatar answered Oct 20 '22 23:10

Bogatyr


You could also do:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.0;
}

This seems to work for my (single) section header and avoids the need for reloadData.

Note that:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

is still called, but its return value seems to be ignored.

like image 20
mts Avatar answered Oct 20 '22 22:10

mts