OGeek|极客世界-中国程序员成长平台

标题: ios - UIControl.sendAction 的选择器的目的是什么? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:37
标题: ios - UIControl.sendAction 的选择器的目的是什么?

UIControl.sendAction 的选择器参数的目的是什么? UIControl.addTarget 接受选择器参数表示发送操作时要调用的函数是有道理的,但是为什么发送事件的 Controller 会指定要调用的函数呢?我缺少一些东西。对于某些上下文,这是我尝试实现的自定义按钮中的一段代码:

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



Best Answer-推荐答案


它不适合你。基本上,你已经看到了幕后。现在把目光移开。系统调用此方法。你永远不应该调用它。理论上你可以覆盖它,但你永远不会这样做。

想发送一个控件事件对应的 Action 时,你调用sendActionsForControlEvents:

关于ios - UIControl.sendAction 的选择器的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33357759/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4