title: Adding method to instance of objective-c class at runtime
body: <p>I am wondering if there is a way to add an instance method to an "instance" of a class.</p>
  
  <p>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.  </p>
  
  <p>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.</p>
  
  <p>Any hints?</p>
  
  <p>Here is the code that I am using, the function that i am trying to add (willDisplayCell_) is not getting called.</p>
  
  <pre><code>- (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?");
  }
  </code></pre>