title: iOS UITableView: assign background color as gradient using CAGradientLayer
body: <p>I just started playing with the Master-Detail view template in Xcode 4.3 and I am trying to change the background color of master and set it to a color gradient.
  Here is what I tried:</p>
  
  <p>Colors.m</p>
  
  <pre><code>#import "Colors.h"
  
  @implementation Colors
  
  + (UIColor *) navigationMenuGradientTop
  {
      return [UIColor colorWithRed:213.0f/255.0f green:91.0f/255.0f blue:92.0f/255.0f alpha:1.0f];
  }
  
  + (UIColor *) navigationMenuGradientBottom
  {
      return [UIColor colorWithRed:188.0f/255.0f green:0.0f/255.0f blue:1.0f/255.0f alpha:1.0f];    
  }
  
  + (CAGradientLayer *) navigationMenuGradient
  {
      NSArray *colors = [NSArray arrayWithObjects:(id)self.navigationMenuGradientTop, self.navigationMenuGradientBottom, nil];
      CAGradientLayer *gradientLayer = [CAGradientLayer layer];
      gradientLayer.colors = colors;
  
      return gradientLayer;
  }
  @end
  </code></pre>
  
  <p>MasterViewController.m</p>
  
  <pre><code>import "Colors.h"
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
  
      CAGradientLayer *bgLayer = [Colors navigationMenuGradient];
      bgLayer.frame = tableView.bounds;
      [tableView.layer insertSublayer:bgLayer atIndex:0];
  
      return cell;
  }
  </code></pre>
  
  <p>Upon running I get the following error in <code>main</code> - <code>Thread 1: EXC_BAD_ACCESS (code=1, address=0xxxxxxxx)</code></p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      @autorelasespool {
          return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
      }
  }
  </code></pre>
  
  <p>I have added the QuartzCore framework to the project as well. What am I missing over here? and what direction should I generally go in when such errors occur (because the build succeeded, app seems to have crashed here)?</p>