我是靠谱客的博主 懵懂玫瑰,这篇文章主要介绍iOS11 SectionHeader 胡乱移动且滑动时出现重复内容的解决方法,现在分享给大家,希望可以做个参考。

升级到iOS 11后,痛苦的事情多起来了,以前版本没有的出现问题的代码,经过Xcode 9一编译,千万草泥马奔腾而过;

今天碰到一个奇葩问题,直接进入主题:

问题描述:

复制代码
1
2
3
4
5
6
7
8
9
10
-(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分割线的偏移)

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
/** * 解决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的头部。

具体代码如下所示:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//自定义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 胡乱移动且滑动时出现重复内容的解决方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对靠谱客网站的支持!

最后

以上就是懵懂玫瑰最近收集整理的关于iOS11 SectionHeader 胡乱移动且滑动时出现重复内容的解决方法的全部内容,更多相关iOS11内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(102)

评论列表共有 0 条评论

立即
投稿
返回
顶部