【问题标题】:uitableviewcell separator line not displaying in full widthuitableviewcell 分隔线未全宽显示
【发布时间】:2015-12-22 14:40:14
【问题描述】:

我正在尝试显示 UITableview 自定义单元格。但我的 tableview 分隔符没有按预期显示。我附上截图。

我尝试制作 UIEdgeInsetZero,但没有成功。谁能帮我解决这个问题。

【问题讨论】:

  • 你不能在故事板上显示约束并设置你的单元格
  • 嗯,你需要将separatorInset 设置为 none 对于UITableView,并且在自定义单元格中,你需要放置距底部 1px 高度的 UIView。

标签: ios iphone uitableview


【解决方案1】:

separatorInset 设置为UIEdgeInsetZero 对于iOS 8 是不够的。您还应该将表格和单元格的layoutMargins 属性设置为UIEdgeInsetZero

【讨论】:

    【解决方案2】:

    请按自定义更改分隔符插图。谢谢。

    【讨论】:

      【解决方案3】:

      试试这个:

      cell.layoutMargins = UIEdgeInsetsZero;
      
      cell.preservesSuperviewLayoutMargins = NO;
      

      【讨论】:

        【解决方案4】:

        嘿,我得到了解决方案。

        我在我的自定义 UITableViewCell 中覆盖 layoutSubviews 并且分隔符正确显示。

        - (void)layoutSubviews {
        [super layoutSubviews];
        
        for (UIView *subview in self.contentView.superview.subviews) {
            if ([NSStringFromClass(subview.class) hasSuffix:@"SeparatorView"]) {
                subview.hidden = NO;
            }
        } }
        

        【讨论】:

          【解决方案5】:
          -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
          {
              // Remove seperator inset
              if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
                  [cell setSeparatorInset:UIEdgeInsetsZero];
              }
          
              // Prevent the cell from inheriting the Table View's margin settings
              if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
                  [cell setPreservesSuperviewLayoutMargins:NO];
              }
          
              // Explictly set your cell's layout margins
              if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
                  [cell setLayoutMargins:UIEdgeInsetsZero];
              }
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-04-05
            • 2014-08-11
            • 2020-05-14
            • 2014-01-24
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-10-15
            相关资源
            最近更新 更多