UITableView的UITableViewStyleGrouped风格顶部空白问题
2016-11-17 14:18
399 查看
在使用UITableView的UITableViewStyleGrouped的属性时,会遇到每组的顶部空白如图1;
处理方法:设置UITableView的两个代理就可以解决:
// 解决方法:1(设置headView在代理方法中操作能避免空白)
-(UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
{
return nil;
}
-(CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section{
return 0.001;
}
//ps:项目需要headView的话就在上边代理中操作即可,如下
-(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];
处理方法:设置UITableView的两个代理就可以解决:
// 解决方法:1(设置headView在代理方法中操作能避免空白)
-(UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
{
return nil;
}
-(CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section{
return 0.001;
}
//ps:项目需要headView的话就在上边代理中操作即可,如下
-(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];
相关文章推荐
- iOS开发笔记之三十二——UITableView的UITableViewStyleGrouped风格顶部空白的设置
- iOS - UITableViewStyleGrouped样式顶部预留空白问题
- iOS开发笔记之四十四——UITableView的UITableViewStyleGrouped风格顶部空白的设置
- UITableViewStyleGrouped 顶部空白
- UITableViewStyleGrouped顶部留白问题
- uitableview style类型为Grouped时,去掉上面空白的方法
- 对于UITableViewStyleGrouped类型的UITableView的背景色设置问题
- UITableViewStyleGrouped 设置表头出现section不为0的问题
- IOS7以上的UITableView顶部空白的问题
- 解决iOS7中,tableView设置UITableViewStyleGrouped后的section之间空余问题
- iOS 去掉UITableView风格为group时候的最顶部的空白距离
- 第16月第25天 tableView设置UITableViewStyleGrouped顶部有空余高度
- 对于UITableViewStyleGrouped类型的UITableView的背景色设置问题
- UITableViewStyleGrouped 模式下 headview 多出一块高度问题
- UITableViewStyleGrouped样式下取消表视图的上方空白区域
- iOS 去掉UITableView风格为group时候的最顶部的空白距离
- UITableViewStyleGrouped的间距问题
- iOS 去掉UITableView风格为group时候的最顶部的空白距离
- UITableView Grouped风格时,设置背景颜色的问题
- tableView设置UITableViewStyleGrouped顶部有空余高度