iOS11 SectionHeader 胡乱移动且滑动时出现重复内容的解决方法
来源:爱站网时间:2020-02-09编辑:网友分享
不管是什么安卓还是IOS系统,都要进行不断的升级,才能适应诸多广大客户,今天爱站技术频道小编带给大家的是iOS11 SectionHeader 胡乱移动且滑动时出现重复内容的解决方法,赶快来学习吧!
不管是什么安卓还是IOS系统,都要进行不断的升级,才能适应诸多广大客户,今天爱站技术频道小编带给大家的是iOS11 SectionHeader 胡乱移动且滑动时出现重复内容的解决方法,赶快来学习吧!
问题描述:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 12;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* headerSection_V = [[UIView alloc]initWithFrame:CGRectMake(ZERODIS, ZERODIS, SCREEN_WIDTH, 12)];
[headerSection_V setBackgroundColor:COLOR_3];
return headerSection_V;
}
1- headerView 会错乱移动, 且调整tableView 的style也没有效果;
2- 滑动tableView的时候, 貌似底部又多出一个图层tableView,重复了tableViewCell的内容;
3- 以下代码无效:(当然tableVIew 懒加载的时候 还有相应代码设置cell分割线的偏移)
/**
* 解决cell分割线距离两边12 居中对齐
*/
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsMake(ZERODIS, 12, ZERODIS, 12)];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsMake(ZERODIS, 12, ZERODIS, 12)];
}
}
最后排查发现:
旧代码使用了xib但是又没有用xib的tableView, tableView又是自己代码生成的, 把xib删除之后,就OK了;
PS:下面通过实例代码给大家分享UITableView SectionHeader 自定义section的头部。
具体代码如下所示:
//自定义section的头部
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 30)];//创建一个视图
UIImageView *headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 300, 30)];
UIImage *image = [UIImage imageNamed:@"4-2.png"];
[headerImageView setImage:image];
[headerView addSubview:headerImageView];
[headerImageView release];
NSString *createTime = [self.keysArray objectAtIndex:section];
createTime = [createTime stringByReplacingCharactersInRange:NSMakeRange(4, 1) withString:@"-"];
createTime = [createTime stringByReplacingCharactersInRange:NSMakeRange(7, 1) withString:@"-"];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 5, 150, 20)];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.font = [UIFont boldSystemFontOfSize:15.0];
headerLabel.textColor = [UIColor blueColor];
headerLabel.text = createTime;
[headerView addSubview:headerLabel];
[headerLabel release];
return headerView;
}
以上是爱站技术频道小编介绍的iOS11 SectionHeader 胡乱移动且滑动时出现重复内容的解决方法,如果我们急用,暂时想不到其他办法,可以套用本文的介绍后再进行改进。
