I am wondering if there is a way to add an instance method to the "instance" of the class.
The scenario is that I am using an EKEventEditViewController, and in this class there is a UITableView with a delegate (UITableViewDelegate) called "EKEventEditor" (non-state AFAIK). It does not implement the tableView: willDisplayCell: forRowAtIndexPath: method, which I am trying to use to disconnect some cell.
So, I'm trying to add a method to an instance, but all I can find in the Obj-C runtime is the call to class_addMethod, which adds the method to the class, but not the instance. If "EKEventEditor" is private, I cannot just expand it and add this method myself.
Any clues?
Here is the code I'm using, the function I'm trying to add (willDisplayCell_) does not receive the call.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if ([navigationController isKindOfClass:[EKEventEditViewController class]]) { UITableViewController *rootController = (UITableViewController*)[(UINavigationController*)navigationController visibleViewController]; if ([rootController isKindOfClass:[UITableViewController class]]) { UITableView *eventTableView = (UITableView*)[rootController view]; class_addMethod([eventTableView.delegate class], @selector(tableView:willDisplayCell:forRowAtIndexPath:), (IMP)willDisplayCell_, " v@ :@@@"); }}} void willDisplayCell_(id self, SEL cmd, UITableView *tableView, UITableViewCell *cell, NSIndexPath *indexPath) { NSLog(@"CALLED?"); }
source share