【发布时间】:2015-06-16 08:21:03
【问题描述】:
我是 Objective C 和 iOS 的新手,所以我的问题可能很愚蠢:)
我在调试模式下检查了 self.tableData,那里没有空项,numberOfSectionsInTableView 返回正确的值。
下面是 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/rm2DL
在视图层次结构中: http://take.ms/oALdi
这个空白空间正好有超过 20 磅的高度,所以我认为它应该是某种奇怪的标题。
【问题讨论】:
标签: ios objective-c uitableview