時(shí)間:2019年1月25日 周五
問(wèn)題:使用tableViewGroup類型,這種類型方便我們分欄,滾動(dòng)時(shí)section的view會(huì)跟著一起動(dòng);
但是出現(xiàn)了一個(gè)異常的情況蓉媳,tableView會(huì)出現(xiàn)空白的區(qū)域,而且是不確定性的空白锅铅,點(diǎn)擊視圖可以看到是UITableViewWrapperView出了問(wèn)題酪呻,百度一下解決方法,但是都不是很好的解決策略盐须,還有很多方法試了也行不通玩荠。
比如:
self.edgesForExtendedLayout = UIRectEdgeNone;
self.automaticallyAdjustsScrollViewInsets = NO;
經(jīng)多次的調(diào)試分析,這個(gè)應(yīng)該是tableView的一個(gè)隱形的bug贼邓。出現(xiàn)在tableView的屬性設(shè)置值阶冈,但是又沒(méi)有實(shí)現(xiàn)的情況下導(dǎo)致,可以推斷tableView在創(chuàng)建的時(shí)候會(huì)取相應(yīng)的值塑径,有值但提供view設(shè)置不對(duì)女坑,就會(huì)使用默認(rèn)值。
1)簡(jiǎn)單的解決方法:就是不使用這些屬性统舀,設(shè)置高度就行了匆骗,如果有自定義的view話,要使用重用機(jī)制誉简。
直接創(chuàng)建返回碉就,這樣是不行的:
return [[UIView new] initWithFrame:(CGRect){0,0,CGRectGetWidth([UIScreen mainScreen].bounds),30}];
2)如果直接給tableView屬性設(shè)置值的時(shí)候,可能出現(xiàn)空白的情況闷串,以及解決方法如下瓮钥。
注意:frame非zero,要使用重用機(jī)制烹吵。
1碉熄、tableheaderview
tableView.tableHeaderView = [UIView new];//會(huì)導(dǎo)致頭部出現(xiàn)空白
解決:要給headerview提供一個(gè)frame非zero的view
2、tablefooterview
tableView.tableFooterView = [UIView new];//底部不會(huì)出現(xiàn)空白
3只损、cell
tableView.estimatedRowHeight = 42;//因?yàn)閷?shí)現(xiàn)了cell,所以不會(huì)出現(xiàn)空白
tableView.rowHeight = 42;//因?yàn)閷?shí)現(xiàn)了cell蛉顽,所以不會(huì)出現(xiàn)空白
4闲勺、section headerview
tableView.estimatedSectionHeaderHeight = 30;//會(huì)導(dǎo)致每行section出現(xiàn)空白
解決方法:
1)要實(shí)現(xiàn)sectionheader的方法癌幕,返回headerview,且frame不能為zero
方法: - (UIView *)tableView: viewForHeaderInSection:
2)view要實(shí)現(xiàn)復(fù)用,不然還會(huì)出現(xiàn)空白
[tableView dequeueReusableHeaderFooterViewWithIdentifier: @"header"];
如:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *headerView = (UILabel *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:TableViewHeaderViewIdentifier];
if (!headerView) {
headerView = [UILabel new];
headerView.backgroundColor = [UIColor whiteColor];
headerView.frame = (CGRect){0,0, CGRectGetWidth([UIScreen mainScreen].bounds),30};
}
headerView.text = [NSString stringWithFormat:@" %@",self.indexArray[section]];
return headerView;
}
5比搭、section footer view
tableView.estimatedSectionFooterHeight = 30;//會(huì)導(dǎo)致每行section出現(xiàn)空白
解決方法:
1)要實(shí)現(xiàn)sectionfooter的方法抄囚,返回footerview蜂挪,且frame不能為zero
方法: - (UIView *)tableView: viewForFooterInSection:
2)view要實(shí)現(xiàn)復(fù)用,不然還會(huì)出現(xiàn)空白
[tableView dequeueReusableHeaderFooterViewWithIdentifier:@"footer"]
如:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 30;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *headerView = (UILabel *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:@"footer"];
if (!headerView) {
headerView = [UIView new];
headerView.backgroundColor = [UIColor whiteColor];
headerView.frame = (CGRect){0,0, CGRectGetWidth([UIScreen mainScreen].bounds),30};
}
return headerView;
}