滚动时 UITableViewCell 上的阴影消失

Tim*_*ent 0 uitableview swift

我有一个带有阴影的单元格的 UITableView。当我上下滚动时,单元格的阴影消失了。因为我认为这是一个重用问题,我已经只使用过这个带有阴影的单元格。这里可能有什么问题?

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        var cell = UITableViewCell()

        switch indexPath.row {
        case 3: cell = shadowBasicCellAtIndexPath(indexPath)
        case 4: cell = contentCellAtIndexPath(indexPath)
        case 5: cell = contentCellAtIndexPath(indexPath)
        case 6: cell = contentCellAtIndexPath(indexPath)
        case 11: cell = contentCellAtIndexPath(indexPath)
        default: cell = basicCellAtIndexPath(indexPath)
        }

        return cell
    }



    func contentCellAtIndexPath(indexPath: NSIndexPath) -> ContentCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(contentCellIdentifier) as! ContentCell
        setTitleForCell(cell, indexPath: indexPath)
        setContentForCell(cell, indexPath: indexPath)
        return cell
    }

    func shadowBasicCellAtIndexPath(indexPath: NSIndexPath) -> ShadowBasicCell {

      //  let cell = tableView.dequeueReusableCellWithIdentifier(shadowBasicCellIdentifier) as! ShadowBasicCell
        let cell = tableView.dequeueReusableCellWithIdentifier(shadowBasicCellIdentifier, forIndexPath: indexPath) as! ShadowBasicCell

       // let cell = ShadowBasicCell(style: <#T##UITableViewCellStyle#>, reuseIdentifier: <#T##String?#>)

        cell.icon.image = upperTableIcons[indexPath.row]
        cell.textlabel.text = upperTableLabels[indexPath.row]
        cell.textlabel.textColor = UIColor.dmvBody1()
        cell.textlabel.font = UIFont.dmvBody1()
        cell.valueLabel.font = UIFont.dmvBody1()
        cell.selectionStyle = UITableViewCellSelectionStyle.None


        cell.layer.shadowColor = UIColor.blackColor().CGColor
        cell.layer.shadowOffset = CGSizeMake(5, 5);
        cell.layer.shadowOpacity = 0.2;
        cell.layer.shadowRadius = 3.0;
        cell.clipsToBounds = false

        let shadowFrame: CGRect = (cell.layer.bounds)
        let shadowPath: CGPathRef = UIBezierPath(rect: shadowFrame).CGPath
        cell.layer.shadowPath = shadowPath
        cell.separatorInset = UIEdgeInsets.init(top: 0, left: cell.frame.width, bottom: 0, right: 0)
        return cell

    }

    func basicCellAtIndexPath(indexPath: NSIndexPath) -> BasicCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(basicCellIdentifier) as! BasicCell
        cell.icon.image = upperTableIcons[indexPath.row]
        cell.textlabel.text = upperTableLabels[indexPath.row]
        cell.textlabel.textColor = UIColor.dmvBody1()
        cell.valueLabel.text = upperTableValues[indexPath.row]
        cell.valueLabel.textColor = UIColor.dmvBody1()
        cell.textlabel.font = UIFont.dmvBody1()
        cell.valueLabel.font = UIFont.dmvBody1()
        cell.selectionStyle = UITableViewCellSelectionStyle.None
        if indexPath.row > 6 {cell.backgroundColor = UIColor.dmvBeige30()} else {
            cell.backgroundColor = UIColor.whiteColor()
        }
       return cell
    }
Run Code Online (Sandbox Code Playgroud)

Tim*_*ent 5

我自己解决了这个问题:没有看到阴影的原因是因为它被下面的单元格覆盖了重绘。我将以下单元格的背景颜色设置为 clearColor() ,现在一切正常。