Grouped UITableView shows blank space when section is empty
iphone, objective-c, uitableview
Solution
In the above screenshot, is your `numberOfSectionsInTableView:` method returning a value of 5? And then is your `getRowCount:` method (called from `numberOfRowsInSection:`) returning a value of 0 for those "missing" sections (e.g. 1, 3 and 4)?
If you don't want gaps in between, the likely solution is to only declare the number of sections you want to be visible. In your example above, you'd only want to return value of 3 from `numberOfSectionsInTableView:`.
Problem
I have a grouped UITableView where not all sections may be displayed at once, the table is driven by some data that not every record may have. My trouble is that the records that don't have certain sections show up as blank spaces in the table. There are no footers/headers. Anything I've missed? ``` - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return [self getRowCount:section]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.text = [NSString stringWithFormat:@"section: %d row: %d",indexPath.section,indexPath.row]; // Configure the cell... return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { float height = 0.0; if([self getRowCount:indexPath.section] != 0){ height = kDefaultRowHeight; } return height; } ```