Skip to content

Instantly share code, notes, and snippets.

@theoknock
Last active November 25, 2022 11:39
Show Gist options
  • Save theoknock/38ebd2868059f2a218f3fe4171a7d18b to your computer and use it in GitHub Desktop.
Save theoknock/38ebd2868059f2a218f3fe4171a7d18b to your computer and use it in GitHub Desktop.
UIControl event handling with blocks
#import <objc/runtime.h>
//
//
//
objc_setAssociatedObject(self.segmentedControl, @selector(invoke), ^{
dispatch_async(dispatch_get_main_queue(), ^{
// event handler-related code
});
}, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self.segmentedControl addTarget:objc_getAssociatedObject(self.segmentedControl, @selector(invoke)) action:@selector(invoke) forControlEvents:UIControlEventAllEvents];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment