title: Bad Access error when accessing a UIColor*
body: <p>In my drawing routine for a custom UITableViewCell, was using the following without any problems:</p>
  
  <pre><code>CGContextRef context = UIGraphicsGetCurrentContext();   
  UIColor* backgroundColor = [UIColor colorForHex:@"FFFEFF"];
  [backgroundColor set];
  CGContextFillRect(context, rect);
  </code></pre>
  
  <p>Of course, this is quite standard except for my interface on the UIColor object for colorForHex which takes a string and breaks this down into RGB values of 0-255 and returns a UIColor object with the following (a is defaulted to 1.0f):</p>
  
  <pre><code>return [UIColor colorWithRed:((float) r/255.0f) green:((float) g/255.0f) blue:((float) b/255.0f) alpha:a];
  </code></pre>
  
  <p>Now this works fine, but I tried to improve this and centralise the the colour (and font) creation to try to speed up the draw routine as much as possible.  This is where I get the problem.</p>
  
  <p>I create a protocol using:</p>
  
  <pre><code>@protocol ItemListTableViewCellDelegate
  -(UIFont*) fontForId:(int) fontID;
  -(UIColor*) colorForId:(int) colorID;
  @end
  </code></pre>
  
  <p>The controller implements this protocol and implements the colorForId method as:</p>
  
  <pre><code>-(UIColor*) colorForId:(int) colorID {
      UIColor* requestedColor = nil;
      switch (colorID) {
          case BACKGROUND_COLOR_ID:
          {
              requestedColor = backgroundColor;
          }
              break;
      }
      return requestedColor;
  }
  </code></pre>
  
  <p>where backgroundColor is created as a member of the controller as a UIColor* in the initWithStyle method of the controller.  This is being called and the backgroundColor is being created.</p>
  
  <p>The cell has an <code>NSObject&lt;ItemListTableViewCellDelegate&gt;* cellDelegate</code> member which is initialised with the controller so that the cell can call </p>
  
  <pre><code>UIColor* backgroundColor = [cellDelegate colorForId:BACKGROUND_COLOR_ID]; 
  </code></pre>
  
  <p>which appears to return the correct pointer to the UIColor in the controller, but when 'set' is called on this colour in the cell draw method then the cell throws a BAD ACCESS error and I can't work out why.</p>
  
  <p>Any pointers in the right direction?</p>