Delete button not showing on UITableViewCell with rounded corners

In my tableview, I have logic in my tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) to determine if a cell has rounded corners on top, bottom, or no rounded corners at all.

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

        if indexPath.row == 0 {
            // round top 2 corners
            let maskLayer = CAShapeLayer()
            maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [UIRectCorner .TopLeft, UIRectCorner .TopRight], cornerRadii: CGSizeMake(4, 4)).CGPath
            cell.layer.mask = maskLayer
        }

        if indexPath.section != 1 {

            if indexPath.row == self.tableView.numberOfRowsInSection(indexPath.section) - 1 {
                let maskLayer = CAShapeLayer()
                maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [UIRectCorner .BottomLeft, UIRectCorner .BottomRight], cornerRadii: CGSizeMake(4, 4)).CGPath
                cell.layer.mask = maskLayer
            }
        }

    }

This works, but after I have implemented editing into the tableview, strange things happen to the delete button.

  • Which is better, setEnabled or setUserInteractionEnabled?
  • List of random numbers - arc4random
  • Fading out any content which approaches edges of UIScollView
  • UIView animations with autoreverse
  • “Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.” when using GCC
  • Set constraints through code to an element from Storyboard with swift iOS8
  • With the rounded corners code:

    with rounded corners

    When I remove the rounded corners:

    without rounded corners

    This really confuses me because I’m not sure what I’m doing wrong. Can anyone help?

    Solutions Collect From Internet About “Delete button not showing on UITableViewCell with rounded corners”

    override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    
            if indexPath.row == 0 {
                // round top 2 corners
                let maskLayer = CAShapeLayer()
                maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [UIRectCorner .TopLeft, UIRectCorner .TopRight], cornerRadii: CGSizeMake(4, 4)).CGPath
                cell.contentView.layer.mask = maskLayer
            }
    
            if indexPath.section != 1 {
    
                if indexPath.row == self.tableView.numberOfRowsInSection(indexPath.section) - 1 {
                    let maskLayer = CAShapeLayer()
                    maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [UIRectCorner .BottomLeft, UIRectCorner .BottomRight], cornerRadii: CGSizeMake(4, 4)).CGPath
                    cell.contentView.layer.mask = maskLayer
                }
            }
    
        }
    

    use cell.contentView.layer.mask = maskLayer