KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I would like to remove section headers from a UITableView if there are no rows for that section. I'm using UILocalizedIndexedCollation for my section headers. So when I create the headers, I don't necessarily know what sections will have content. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. //return [customerSections count]; if (tableView == self.searchDisplayController.searchResultsTableView) { return 1; } return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] count]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { //NSLog(@"Section: %i", section); if (tableView == self.searchDisplayController.searchResultsTableView) { return self.filteredCustomers.count; } else { return [[self.customerData objectAtIndex:section] count]; } } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { // The header for the section is the region name -- get this from the region at the section index. if (tableView == self.searchDisplayController.searchResultsTableView) { return nil;//@"Results"; } return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] objectAtIndex:section]; } - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { //return [customerSections allKeys]; if (tableView == self.searchDisplayController.searchResultsTableView) { return nil; } return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { return [[UILocalizedIndexedCollation currentCollation] sectionForSectionIndexTitleAtIndex:index]; }
Tags (comma-separated)
Save Edits
Cancel