Tôi muốn loại bỏ tiêu đề phần khỏi UITableView nếu không có hàng nào cho phần đó.Xóa các phần không có hàng từ UITableView
Tôi đang sử dụng UILocalizedIndexedCollation
cho tiêu đề phần của tôi. Vì vậy, khi tôi tạo tiêu đề, tôi không nhất thiết phải biết phần nào sẽ có nội dung.
- (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];
}
Mặc dù tôi đã kết thúc tháo sectionIndexTitles cũng này trả lời câu hỏi tốt hơn so với câu trả lời ở trên. – Bot