title: UITableView bad access crashes on dequeueReusableCellWithIdentifier with Storyboard (iOS5)
body: <p>I'm using Storyboards in a new app I'm making and have a tableview in most of my viewcontrollers, they are all set up almost identically to one another; with a prototype cell, a unique cellidentifier, all UI aspects are pretty much the same. Delegate and dataSource are both correctly connected. The app is running flawlessly on iOS6 and the latest iOS7 beta, the problem is that 2 of the view controllers are crashing under iOS5.</p>
  
  <p>The crash (bad access) occurs in the following delegate method when calling <code>dequeueReusableCellWithIdentifier</code>.</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"MoreCell";
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
      // Configure the cell...
  
      // Rest of code snipped ...
  
  }
  </code></pre>
  
  <p>Error messages vary, from nothing at all, to either of these:</p>
  
  <pre><code>*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UITableViewReorderingSupport removeFromSuperview]: unrecognized selector sent to instance 0x2a3e20'
  </code></pre>
  
  <p>or</p>
  
  <pre><code>*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayer removeFromSuperview]: unrecognized selector sent to instance 0x2b9f90'
  </code></pre>
  
  <p>There was also a third error involving <code>NSInvocation removeFromSuperview</code> but I no longer get this one.</p>
  
  <p>I can't see any obvious issues in the nibs in the storyboard. As I said before they are all configured virtually identical, so it makes no sense for this crash to only occur on certain view controllers. I don't have autolayout ticked either so that's not a problem.</p>
  
  <p>If I create the cell the old-fashioned way (pre-storyboards), it works fine. But I don't want to have to do that, and I shouldn't have to as defeats the point of using storyboards...</p>
  
  <pre><code>if (cell==nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
      cell.textLabel.textColor = [UIColor colorWithRed:(100/255.0f) green:(150/255.0f) blue:(50/255.0f) alpha:1.0];
      cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:17.0];
      cell.detailTextLabel.textColor = [UIColor colorWithRed:(85/255.0f) green:(85/255.0f) blue:(85/255.0f) alpha:1.0];
      cell.detailTextLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:15.0];
  }
  </code></pre>
  
  <p>The above works fine if I comment out the <code>dequeueReusableCellWithIdentifier</code> line before it.</p>
  
  <p>So it seems the problem must be within the storyboard, yet I can't see anything wrong with it when I compare it to the viewcontrollers which are working fine.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>After posting this question I deleted one of the problematic viewcontrollers and added it again from scratch. In doing this I have found the root cause of the problem - connecting a view to the cell for its <code>selectedBackgroundView</code>. This exact view is being used in other tables in my app just fine, but on this particular one it causes a crash as above, and I have absolutely no idea why. I don't have any code that modifies it in anyway. It's just connected in the nib and that's it...</p>
  
  <p>I can work around this by creating the selectedBackgroundView in code but I still don't understand what's different about this.</p>