Ios UIControl如何管理其目标?

Ios UIControl如何管理其目标?,ios,target,uicontrol,Ios,Target,Uicontrol,苹果公司: 请注意,不会保留目标 在UIControl+BlocksKit.m中时 // the action cannot be NULL. Note that the target is not retained. - (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; 那么UIControl如何管理目标,为什么不释放目标?bk\u a

苹果公司:

请注意,不会保留目标

在UIControl+BlocksKit.m中时

// the action cannot be NULL. Note that the target is not retained.
- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

那么
UIControl
如何管理目标,为什么不释放目标?

bk\u addEventHandler:forControlEvents:方法通过将其添加到
NSMutableSet
来保留
BKControlWrapper
实例。该集合由控件本身保留的
events
字典保留,因为字典使用
OBJC\u ASSOCIATION\u RETAIN\u NONATOMIC
与控件关联


您传递给
bk\u addEventHandler:forControlEvents:
的块不创建保留循环,这是一种导入。您必须通过确保块在需要时使用弱引用来执行此操作(例如,如果它需要引用视图控制器而不是引用控件)。

UIControl目标不会被释放,因为它没有被保留。
BKControlWrapper *target = [[BKControlWrapper alloc] initWithHandler:handler forControlEvents:controlEvents];
[handlers addObject:target];
[self addTarget:target action:@selector(invoke:) forControlEvents:controlEvents];