UITableViewStyleGrouped时,tableview 的section 会出现空隙是为什么啊。。
UITableViewStyleGrouped时,tableview 的section 会出现空隙是为什么啊。。
UITableViewStylePlain 时,使用了,UITableView的 sectionHeader,header移动会有问题,,
tableview 的style是UITableViewStylePlain时,sectionHeader顶部留白的距离是由contentInset.top的值决定的。如果不设置宏,顶部的距离就是增加了header与bar的高度。
如果tableview的style是UITableViewStyleGrouped的话,sectionHeader是不受影响的。请问,你的section出现空隙是每个section都有吗?
@Roylee-ML 在你的工程文件 CustomTableView 里加入这些代码,就可以看到效果了,,求助啊。。。大神,UITableViewStyleGrouped时,第一个section 没有,其他都有。。。UITableViewStylePlain ,sectionheader 不会和tableview 一起上移。。。
//self = [super initWithFrame:frame style:UITableViewStyleGrouped];
//self = [super initWithFrame:frame style:UITableViewStylePlain];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 60;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor redColor];
return view;
}
tableview 的style是UITableViewStylePlain,sectionHeader顶部留白的距离是contentInset.top的值。如果不设置宏,这个距离就增加了顶部header与segmentbar的高度。设置了宏之后,demo中默认顶部的inset是64,所以在UITableViewStylePlain下,sectionheader会悬停在64的位置。
所以,可以采用UITableViewStyleGrouped的方式,是不做悬停处理的。但是group样式的tableview默认都会有section 的header与footer的。所以,如果不要footer,footer的高度要设置做够小(设置0,tableview会认为没设置,就会采用默认高度)。另外,section header最好要加frame的。
self = [super initWithFrame:frame style:UITableViewStyleGrouped];
....
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 60;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.001;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.st_width, 60)];
view.backgroundColor = [UIColor redColor];
return view;
}
这样,并未发现问题
@Roylee-ML 多谢大神,指点啊!!!UITableViewStyleGrouped 方式解决了!! 你说的宏是指 #define ST_PULLTOREFRESH_HEADER_HEIGHT xx 这个宏吗?
是的。