小编给大家分享一下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胡乱移动且滑动时出现重复内容怎么办”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。