滚动时,UITableViewCell上的阴影消失

时间:2015-11-04 21:39:51

标签: swift uitableview

我有一个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
    }

1 个答案:

答案 0 :(得分:4)

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