我对客观的C和iOS有点新手,所以我的问题可以是愚蠢的:) 我在调试模式下检查了self.tableData,没有空的项目那里,并且numberOfSectionsInTableView
返回正确的值。 下面是UITableView的数据源方法:UITableView(分组)在底部添加额外的空头
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *arr = self.tableData[section];
return arr.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.sortedDates.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
NSLog(@"%d", [tableView.dataSource tableView:tableView numberOfRowsInSection:section]);
if ([tableView.dataSource tableView:tableView numberOfRowsInSection:section] == 0) {
return 0;
} else {
return 20.0f;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *footer = [[UIView alloc] initWithFrame: CGRectZero];
footer.backgroundColor = [UIColor whiteColor];
return footer;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if(section < self.sortedDates.count) {
UILabel *sectionHeader = [[UILabel alloc] initWithFrame:[tableView rectForHeaderInSection:section]];
//Setting header appearance
return sectionHeader;
} else {
UIView *blankHeader = [[UIView alloc] initWithFrame: [tableView rectForHeaderInSection:section]];
blankHeader.backgroundColor = [UIColor whiteColor];
return blankHeader;
}
}
这里就是我得到:
在模拟器在视图层次: http://take.ms/oALdi
这个空白正好有超过身高20点,所以我认为它应该是某种奇怪的标题。
谢谢你,罗里。这个帮助: ' - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01; }' –