Tôi có UITableView được nhóm theo đó không phải tất cả các phần có thể được hiển thị cùng một lúc, bảng được điều khiển bởi một số dữ liệu mà không phải mọi bản ghi có thể có. rắc rối của tôi là các hồ sơ mà không có bộ phận nào đó xuất hiện khoảng trống như trống trong bảng (xem hình)UITableView được nhóm lại hiển thị không gian trống khi phần trống rỗng
alt text http://img220.imageshack.us/img220/5633/screenshot20100322at228.png
Không có footers/tiêu đề. Bất cứ điều gì tôi đã bỏ lỡ?
- (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, nhờ cho công tác điều tra! –
Phương pháp ít xâm nhập nhất mà tôi đã tìm thấy cho đến bây giờ là trả về 1 cho heightForHeaderInSection và heightForFooterInSection 'if ([tự tableView: tableView numberOfRowsInSection: section] == 0)' và trả về một khung nhìn có kích thước bằng không cho 'viewForHeaderInSection' /' viewForFooterInSection 'nếu số hàng là 0. –
Cảm ơn! Cảm ơn! Freaking Apple. Nó sẽ thực sự tốt đẹp nếu họ ghi lại những thứ như một thực tế rằng trở về 0 cho chiều cao trong đại biểu không ghi đè khoảng cách chuẩn. Có quá nhiều trường hợp cạnh API tinh tế mà Apple không ghi lại. – smparkes