Swift willTransition(to state:) warning

Hello. In my UITableViewController, I have a custom UITableViewCell. I have added an option to delete a specific row in the table. Based on the comments that I have found on-line, the following was added to the subclass of UITableViewCell:


override func willTransition(to state: UITableViewCellStateMask)
    {
        super.willTransition(to: state)
      
        if (state  == UITableViewCellStateMask.showingDeleteConfirmationMask)
        {
            for subview in self.subviews as [UIView]
            {
                // THIS IS WHERE THE WARNING IS SHOWN
                if (subview is UITableViewCellEditingStyle )
                {
                    let deleteBtn : UIImageView = UIImageView(frame: CGRect(x: 0,
                                                                            y: 0,
                                                                            width: 64,
                                                                            height: 33))
                    deleteBtn.image = UIImage(named: "image.png")
                    subview.subviews[0].addSubview(deleteBtn)
                }
            }
        }
    }


Everything works just fine, however xCode shows a warning that "Cast from 'UIView' to unrelated type 'UITableViewCellEditingStyle' always fails". Is there another way to implement it?


Thanks a lot!

Accepted Reply

I think you want

UITableViewCell
rather than
UITableViewCellEditingStyle
. The former is a UIView subclass, which might sense in this context, whereas the latter is an enum.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

I think you want

UITableViewCell
rather than
UITableViewCellEditingStyle
. The former is a UIView subclass, which might sense in this context, whereas the latter is an enum.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"