Last active
November 25, 2022 11:39
-
-
Save theoknock/38ebd2868059f2a218f3fe4171a7d18b to your computer and use it in GitHub Desktop.
UIControl event handling with blocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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