1 Reply
      Latest reply on Mar 9, 2017 2:48 AM by eskimo
      igorland Level 1 Level 1 (0 points)

        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")


        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!

        • Re: Swift willTransition(to state:) warning
          eskimo Apple Staff Apple Staff (12,455 points)

          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"