I would like to customize the image in the accessory views of some tables while allowing to pass the table and indexPath to the accessoryButtonTappedForRowWithIndexPath callback including the clicked table. I used to employ the UIControl+Blocks.h class here reported:
@implementation UIControl (Blocks)
- (void)addEventHandler:(ActionBlock)handler forControlEvents: (UIControlEvents)controlEvents
{
objc_setAssociatedObject(self, &UIButtonHandlerKey, handler, OBJC_ASSOCIATION_COPY_NONATOMIC);
[self addTarget:self action:@selector(callActionHandler:event:) forControlEvents:controlEvents];
}
- (void)callActionHandler:(id)sender event:(id)event
{
ActionBlock handler = (ActionBlock)objc_getAssociatedObject(self, &UIButtonHandlerKey);
if (handler) {
handler(sender, event);
}
}
@end
But it started behaving weirdly by sometimes returning the button in the place of the event so crashing my app when I try to get allTouches and so I am fervidly looking for a replacement.
I also tried replacing the original (i) accessory button, but in this way I also lose the accessibilityLabel. Please help.
我预见到了表重新加载的问题,从而恢复了旧的解决方案,以防按钮发疯并开始将自身发送为控件事件。
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.