У меня есть сгруппированный UITableView, где не все секции могут отображаться сразу, таблица управляется некоторыми данными, которые не каждая запись может иметь. Моя беда в том, что записи, которые не имеют определенные разделы отображаются как пустые места в таблице (см рисунка)Сгруппированный UITableView показывает пустое место, когда раздел пуст
alt text http://img220.imageshack.us/img220/5633/screenshot20100322at228.png
Там нет колонтитулов/заголовков. Все, что я пропустил?
- (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;
}
Nice, спасибо за следственную работу! –
Наименее навязчивый метод, который я нашел до сих пор, - это вернуть 1 для heightForHeaderInSection и heightForFooterInSection 'if ([self tableView: tableView numberOfRowsInSection: section] == 0)' и вернуть представление с нулевым размером для 'viewForHeaderInSection' /' viewForFooterInSection 'если количество строк равно 0. –
Спасибо! Благодаря! Внезапное яблоко. Было бы очень приятно, если бы они задокументировали такие вещи, как то, что возвращение 0 для высот в делегате не отменяет стандартного интервала. Есть слишком много тонких случаев API, которые Apple не документирует. – smparkes