【问题标题】:UITableView shows sometimes a separating line between the cells, on the iPhone, not on the iPadUITableView 有时会在 iPhone 上而不是 iPad 上显示单元格之间的分隔线
【发布时间】:2015-03-25 12:37:01
【问题描述】:

我有一个带有动态tableViewCellstableView,并且分隔符属性设置为none
每个单元格具有单元格高度的 3 个subviews,此处称为backgroundViews,以相等的宽度并排放置。它们呈现背景颜色。
这些backgroundViews 中的每一个都有一个imageView 作为自己的subviewimageView 的大小与其 backgroundView 相同。
tableViewCell 及其子视图由 autolayout 布局,即 imageViews 到它们的 backgroundView 的边距为 0,而 3 个 backgroundViewstableViewCell 顶部和底部的边距为0,左侧backgroundView 到单元格左边缘的边距为0,右侧backgroundView 有边距0 到右单元格边缘,并且所有 3 个 backgroundViews 具有相等的宽度。

在最简单的情况下,imageViewsimage 属性是 nil,因此 backgroundViews 的彩色背景是可见的。
当我在 iPad(模拟器或设备)上运行应用程序时,一切看起来都很好。
当我在 iPhone(模拟器或设备)上运行它时,某些单元格之间有时会有很少的分隔线,可能高 1 点(在下面的屏幕截图中第 2 和第 5 个单元格)。
该分隔线与 backgroundViews 无关,因为它们具有背景色,并且分隔线是白色的。它既不与tableViewCell 相关,也不与contentView 相关,因为两者都有清晰的背景颜色。它与tableView 本身无关,因为它的背景颜色设置为黑色。
我不知道这条分隔线是从哪里来的,也不知道为什么它只出现在 iPhone 上,而不是 iPad 上。 欢迎任何建议我如何摆脱这些烦人的线条。

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    问题如下:
    我将tableViewCell 的宽度除以 3,并将tableViewrowHeight 属性设置为相同的值,以并排获得 3 个正方形。
    在 iPad 上,行高为 768/3 = 256,一个整数值。
    在 iPhone 上,行高是 320/3 = 106.66666666666667,一个小数值。因此,行高无法 1:1 映射到屏幕点。
    当我将行高四舍五入时

    self.tableView.rowHeight = ceil(fieldWidth);
    

    问题消失了。

    【讨论】:

      【解决方案2】:

      接受的答案对我不起作用。但是,在单元格上设置 clipsToBounds 属性会有所帮助

      override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
          let cell = tableView.dequeueReusableCellWithIdentifier( ... )
          ...
          cell.clipsToBounds = true
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-28
        • 1970-01-01
        • 2023-04-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多