addTarget:action:forControlEvents: 方法是如何编程的?
在 UIKit 中,UIControl 有以下方法:
addTarget:action:forControlEvents:
removeTarget:action:forControlEvents:
我很想知道这些方法是如何编程的。有人可以指出这些方法如何编程的资源(或提供如何编程的示例)吗?
我已经为我自己的正在运行的项目实现了类似的东西。然而,如果能知道解决这个问题的最佳技术,或者苹果是如何实现它的,那就太好了,因为它是一个有用的模式。 (而且,如果我是正确的,它与委托模式不同?)。
In UIKit, UIControl has the following methods:
addTarget:action:forControlEvents:
removeTarget:action:forControlEvents:
I am interested to know how these are programmed. Could someone point to a resource of how these methods are programmed (or provide an example how these are programmed)?
I have implemented something similar for my own project that is working. However it would be great to know the best technique to go about this, or how Apple have implemented it, as it is a useful pattern. (And, if I am correct, differs from a delegate pattern?).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很简单。这是您可以想象的一种工作方式:(
使用
@implementation
来综合这些属性)然后:
删除就是简单地从适当的数组中远程远程对对象,并且发送事件只是像这样:
当然,这不是实际的代码。但代码就在我面前,这就是一般原则。 :)
It's pretty simple. Here's one way you could imagine it working:
(with an
@implementation
to just synthesize those properties)Then:
Removal would be to simply remote the pair object from the appropriate array, and sending the events would simply be something like this:
Of course, that's not the actual code. But having the code here in front of me, it is the general principle. :)