在使用UITableView的UITableViewStyleGrouped的属性时,会遇到每组的顶部空白如图1;
处理方法:设置UITableView的两个代理就可以解决:
{
return nil ;
return 0.001 ;
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
switch (section) {
case 0:
return _SectionOne;
break;
case 1:
return _SectionTwo;
break;
case 2:
return _SectionThree;
break;
default:
break;
}
return [UIView new];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 120.0;
}
_SectionOne = [[UIImageView alloc] init];
_SectionOne.frame = CGRectMake(0, 0, kScreenWidth, 200);
_SectionOne.backgroundColor = [UIColor grayColor];
// 解决方法:2
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-64) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.sectionFooterHeight = 0.0;//如果分组处理每组的foot还会有35像素的距离,加上此属性即可.
_tableView.sectionHeaderHeight = 0.0;//方法2:处理方法设置headView的高度为0即可。
[self.view addSubview:_tableView];