Android Event-Listener和iOS Target-Action之间的区别?

时间:2021-03-06 20:09:21

I am a Android developer ,Currently I was learning iOS development.And Confused about the target-action pattern. In android if i want to get a callback when a button clicked,I can do like this:

我是一名Android开发人员,目前我正在学习iOS开发。并且对目标行动模式感到困惑。在android中如果我想在单击按钮时获得回调,我可以这样做:

btn.setOnClickListener(myOnClickListener);

It's just like the delegate-pattern in iOS ,But Why Apple choose the target-action pattern for the gestureReconginer event handle?

它就像iOS中的委托模式,但为什么Apple为gestureReconginer事件句柄选择目标动作模式?

Sorry for my poor english skill,Thanks you guys in advance.

抱歉我的英语技能很差,谢谢你们提前。

1 个解决方案

#1


0  

Using target-action, you assign one method of one instance (=target) to one event (=action), whereas delegation would assign one instance implementing a dedicated protocol (equivalent to Java interface) to one event source that then calls the (maybe multiple) methods of that protocol-implementing instance.

使用target-action,将一个实例(= target)的一个方法分配给一个事件(= action),而委托会将一个实现专用协议(相当于Java接口)的实例分配给一个事件源,然后调用(也许)该协议实现实例的多个方法。

I'm not sure anyone can answer why they did it this way, except a software designer/architect of Apple. Nevertheless, target-action has the potential of being transferable to closure syntax.

除了Apple的软件设计师/架构师之外,我不确定是否有人能够回答他们为什么这样做。然而,目标动作有可能转移到闭包语法。

#1


0  

Using target-action, you assign one method of one instance (=target) to one event (=action), whereas delegation would assign one instance implementing a dedicated protocol (equivalent to Java interface) to one event source that then calls the (maybe multiple) methods of that protocol-implementing instance.

使用target-action,将一个实例(= target)的一个方法分配给一个事件(= action),而委托会将一个实现专用协议(相当于Java接口)的实例分配给一个事件源,然后调用(也许)该协议实现实例的多个方法。

I'm not sure anyone can answer why they did it this way, except a software designer/architect of Apple. Nevertheless, target-action has the potential of being transferable to closure syntax.

除了Apple的软件设计师/架构师之外,我不确定是否有人能够回答他们为什么这样做。然而,目标动作有可能转移到闭包语法。