booker
booker

Reputation: 1286

Show section header of UITableView even when it's empty

I'd like to show the section header of my table view even when there is no object in my section.

None of these methods are called for my empty section:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

EDIT : I found the answer.

I was sending 0 to numberOfSectionsInTableView when I got no object that's why thoses methods wasn't call.

So even when a section is empty, my header is shown

Upvotes: 5

Views: 7109

Answers (2)

booker
booker

Reputation: 1286

I found the answer.

I was sending 0 to numberOfSectionsInTableView when I got no object that's why thoses methods wasn't call.

So even when a section is empty, my header is shown

Upvotes: 11

alex
alex

Reputation: 2484

So try to put at least a placeholder object in your section. You can set a default text or information in your corresponding UITableViewCell. Or you even might set a default cell's height to a low value with

- (CGFloat)tableView:(UITableView *)tableView 
  heightForRowAtIndexPath:(NSIndexPath *)indexPath

Upvotes: 0

Related Questions