Reputation: 1268
I have a UITableView that has one cell with a shadow. When I do scrolling up and down, the shadow of the cell disappears. As I thought this was a reuse-issue I already only ever use this one cell with a shadow.What may be the problem here ?
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
}
Upvotes: 0
Views: 1698
Reputation: 1268
I solved the problem myself: The reason the shadow wasn't seen, was because it was covered by the cell beneath that got redrawn. I set the background color of the following cell to clearColor() and everything is fine now.
Upvotes: 5