代码之家  ›  专栏  ›  技术社区  ›  user3051673

TabLVIEW滚动获取错误的最后一个单元格

  •  0
  • user3051673  · 技术社区  · 8 年前

    我正在尝试重新创建脸谱网设置页面

    这就是脸谱网设置页面的样子:

    https://gfycat.com/SizzlingSorrowfulGrayfox

    我已经启动了一个新项目,只使用1个TabLVIEW,使用样式分组、节和头。

    我想绕过TabVIEW的每个部分。我必须将标题的左上角和右上角(节的顶部)以及最后一个单元格的左下角和右下角(节的底部)围起来。

    我已经完成了上面的部分,使用下面的代码 HeaderTableViewCell :

    let rectShape = CAShapeLayer()
    rectShape.bounds = self.frame
    rectShape.position = self.center
    rectShape.path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [.topLeft , .topRight], cornerRadii: CGSize(width: 10, height: 10)).cgPath
    self.layer.mask = rectShape
    

    然而,当我为最后一个细胞做同样的事情时,奇怪的事情发生了。

    https://gfycat.com/UnselfishCommonFlee

    当第一次加载页面时,角点是正确的圆角,但是当我向下和向上滚动时,第二个最后的单元格是圆角。

    这是我在最后一个牢房的密码 cellForRowAt :

    if indexPath.row + 1 == childArray?.count { //last cell, set corner radius
    
        print("is last cell")
        let rectShape = CAShapeLayer()
        rectShape.bounds = rowDataCell.frame
        rectShape.position = rowDataCell.center
        rectShape.path = UIBezierPath(roundedRect: rowDataCell.bounds, byRoundingCorners: [.bottomLeft , .bottomRight], cornerRadii: CGSize(width: 10, height: 10)).cgPath
        rowDataCell.layer.mask = rectShape
    }else{
        rowDataCell.layer.cornerRadius = 0
    }
    

    有什么帮助吗?

    1 回复  |  直到 8 年前
        1
  •  3
  •   rmaddy    8 年前

    电池被重复使用。必须重置您有条件设置的任何属性。

    你设置图层的 mask 对于最后一个单元格,但当单元格不是最后一个单元格时,您不能清除该掩码。

    if indexPath.row + 1 == childArray?.count { //last cell, set corner radius
        print("is last cell")
        let rectShape = CAShapeLayer()
        rectShape.bounds = rowDataCell.frame
        rectShape.position = rowDataCell.center
        rectShape.path = UIBezierPath(roundedRect: rowDataCell.bounds, byRoundingCorners: [.bottomLeft , .bottomRight], cornerRadii: CGSize(width: 10, height: 10)).cgPath
        rowDataCell.layer.mask = rectShape
    }else{
        rowDataCell.layer.mask = nil
    }
    
        2
  •  0
  •   Muhammad Ahmad    6 年前

    下面是一个简单的方法来解决这个问题,只需在表视图单元格的末尾添加这行代码 rowdatacell.layer.mask=无

    推荐文章