viewForHeaderInSection - What to return for no header?
ios, objective-c, uitableview
Solution
Whenever you implement the `viewForHeaderInSection` method you must also implement the `heightForHeaderInSection` method. Be sure to return `0` for the height for sections that have no header.
Problem
I have a `UIViewController` with several `UITableView`s imbedded in it. For some of the tables, I need to show a custom header view with multiple labels. For other tables, I don't want to show a header at all (that is, I want the first cell in `myTable2` to be right at the top of the frame for `myTable2`). Here's roughly what I have: ``` - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (tableView == self.myTable1) // Wants Custom Header { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.contentSize.width,20); // ... Do stuff to customize view ... return view; } elseIf (tableView == self.myTable2) // Wants No header { return nil; // also tried // return [[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)]; // but that didn't work either } } ``` This works great for the custom headers, but for the tables where I don't want any header, it's showing a white box. I figured that `return nil;` would prevent any header from being shown for that table. Is that assumption correct? Is there something else overwritting that? How can I make it so nothing shows?