简体   繁体   中英

Difference between Android Event-Listener and iOS Target-Action?

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:

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?

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM