2015-06-16 43 views
0

我对客观的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/rm2DL

在视图层次: http://take.ms/oALdi

这个空白正好有超过身高20点,所以我认为它应该是某种奇怪的标题。

回答

0

而不是返回页脚的CGRectZero视图,只需返回nil。

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    return nil; 
} 

而且你似乎并没有把实施heightForFooterInSection:section。那应该返回0.0。

这似乎已经出现之前,它似乎iOS经常垫底部20pts。 SO问题涉及iOS6,但我注意到与iOS8.3相关的评论,所以可能仍然相关。 Grouped UITableView has 20px of extra padding at the bottom

+0

谢谢你,罗里。这个帮助: ' - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01; }' –

0

你确定它不是你正在返回的页脚视图吗? 尝试更改footerForSection方法那里只返回零

+0

试过了,结果仍然是一样的。但返回零视图比我的解决方案更清晰。所以谢谢:) –

相关问题