栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > iOS

iOS11 SectionHeader 胡乱移动且滑动时出现重复内容的解决方法

iOS 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

iOS11 SectionHeader 胡乱移动且滑动时出现重复内容的解决方法

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

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

问题描述:

-(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分割线的偏移)


- (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 胡乱移动且滑动时出现重复内容的解决方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/166415.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号