Delete button not showing on UITableViewCell with rounded corners

三世轮回 提交于 2019-12-23 00:41:28

问题


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.

With the rounded corners code:

When I remove the rounded corners:

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


回答1:


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



来源:https://stackoverflow.com/questions/38087659/delete-button-not-showing-on-uitableviewcell-with-rounded-corners

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!