title: Overriding -performSelector: in UIBarButtonItem Subclass
body: <p>I am trying to subclass <code>UIBarButtonItem</code> to add some special functionality. I need the <code>barButtonItem</code> to toggle its appearance when touched, and am therefore attempting to override <code>performSelector:</code>.</p>
  
  <p>When I use the code below, I get an <code>EXC_BAD_ACCESS (code=2 ...)</code></p>
  
  <pre><code>-(id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2
  {
      // Do something
  
      return [super performSelector:aSelector withObject:object1 withObject:object2];
  }
  </code></pre>
  
  <p>My guess is that I am either wrongly attempting to override <code>performSelector:</code> (is there another way?) or incorrectly calling the method on <code>super</code>.</p>
  
  <p>After searching for a solution for 3+ hours I have found nothing. Any help is greatly appreciated.</p>
  
  <p><strong>Update:</strong>
  The following works:</p>
  
  <pre><code>@implementation CustomBarButtonItem
  
  - (void)setTarget:(id)target
  {
      _realTarget = target;
      super.target = self;
  }
  
  - (void)setAction:(SEL)action
  {
      _realAction = action;
      super.action = @selector(pressed);
  }
  
  - (void)pressed
  {
      [self doCustom]; // implement this somewhere
      [_realTarget performSelector:_realAction withObject:nil afterDelay:0];
  }
  </code></pre>
  
  <p>Unfortunately I wanted to toggle between having a <code>customView</code> and the normal <code>UIBarButtonItem</code> look by setting <code>self.customView = nil</code> which only works sometimes. But that is a-whole-nother question. Thanks all.</p>
  
  <p>I will wait a little longer to choose a best answer to see if there are better solutions.</p>