addTarget:action:forControlEvents:实现原理?
答案:2 悬赏:50 手机版
解决时间 2021-02-28 13:13
- 提问者网友:放下
- 2021-02-27 16:59
addTarget:action:forControlEvents:实现原理是什么?另外如何自定义和触发event?
最佳答案
- 五星知识达人网友:摆渡翁
- 2021-02-27 17:36
A control maintains an internal dispatch table: for each control event there is some number of target-action pairs, of which the action is a selector (the name of a method) and the target is the object to which that message is to be sent. When a control event occurs, the control consults its dispatch table, finds all the targer-action pairs associated with that control event, and sends each action message to the corresponding target.控件处理触屏事件,然后调用sendActionsForControlEvents,然后查找这个dispatch table,最后调用相关的方法
全部回答
- 1楼网友:迟山
- 2021-02-27 18:25
第一个不清楚第二个可以这样:接收、处理消息:[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventHandler:) name:@"eventType" object:nil ];-(void)eventHandler: (NSNotification *) notification{ NSLog(@"event triggered");}发送消息:[[NSNotificationCenter defaultCenter] postNotificationName:@"eventType" object:nil ];
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯