I am wondering if there is a way to add an instance method to an "instance" of a class.
The scenario is that I am using EKEventEditViewController and there is a UITableView inside this class with a delegate(UITableViewDelegate) called "EKEventEditor" (non-public AFAIK). It does not implements the tableView:willDisplayCell:forRowAtIndexPath: method, which I am trying to use to disable some cell.
So I am trying to add a method to the instance, but all I can find in the Obj-C runtime is the class_addMethod call which adds method to the class but not the instance. With "EKEventEditor" being private, I can t just extend it and add that method myself.
Any hints?
Here is the code that I am using, the function that i am trying to add (willDisplayCell_) is not getting called.
- (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?");
}