Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of UIControl.sendAction's selector?

Tags:

ios

uicontrol

What is the purpose of UIControl.sendAction's selector argument? It makes sense that UIControl.addTarget takes the selector argument that represents the function that is to be called when an action is sent, but why would the controller that's sending the event specify a function to be called? There's something that I'm missing. For some context, here's a piece of code from the custom button that I'm trying to implement:

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    self.pressed = false
    if self.bounds.contains(touches.first!.locationInView(self)) {
        // sendAction(???, to: nil, forEvent: UIControlEvents.TouchUpInside)
    }

    super.touchesEnded(touches, withEvent: event)
}
like image 766
Christopher Simmons Avatar asked Sep 13 '25 00:09

Christopher Simmons


1 Answers

It's not for you. Basically, you've looked behind the curtain. Now look away. The system calls this method. You should never call it. In theory you could override it but you're never going to.

When you want to send the action corresponding to a control event, you call sendActionsForControlEvents:.

like image 122
matt Avatar answered Sep 15 '25 14:09

matt