0

I want to pass the parameter width in the selector rotation function which passes the size.width.

#selector(rotated(width: size.width))

But it's giving me the following error:

Argument of '#selector' does not refer to an '@objc' method, property, or initializer

Any idea how to solve this?

public override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    coordinator.animate(alongsideTransition: { _ in
        self.setupConstraints()
        self.tableView?.reloadTableData()
    }, completion: { _ in })
    NotificationCenter.default.addObserver(self, selector: #selector(rotated(width: size.width)), name: UIDevice.orientationDidChangeNotification, object: nil)
}
    
@objc func rotated(width: CGFloat) {
   self.widthAnchorConstraint = tableView?.widthAnchor.constraint(equalToConstant: width)
}
ldo1985
  • 25
  • 3
  • https://stackoverflow.com/questions/43251708/passing-arguments-to-selector-in-swift ? – Larme Jun 03 '22 at 07:55
  • Unrelated, but you are adding an observer each time `viewWillTransition(to:with:)`is called? Why don't you just call the method inside it? – Larme Jun 03 '22 at 07:56
  • 1
    Selectors don't allow arguments, they are merely method names. What exactly do you want to accomplish with the given code? – Cristik Jun 03 '22 at 08:56

0 Answers0