Reputation: 975
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.
The crash (bad access) occurs in the following delegate method when calling dequeueReusableCellWithIdentifier
.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MoreCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
// Rest of code snipped ...
}
Error messages vary, from nothing at all, to either of these:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UITableViewReorderingSupport removeFromSuperview]: unrecognized selector sent to instance 0x2a3e20'
or
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayer removeFromSuperview]: unrecognized selector sent to instance 0x2b9f90'
There was also a third error involving NSInvocation removeFromSuperview
but I no longer get this one.
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.
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...
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];
}
The above works fine if I comment out the dequeueReusableCellWithIdentifier
line before it.
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.
UPDATE:
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 selectedBackgroundView
. 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...
I can work around this by creating the selectedBackgroundView in code but I still don't understand what's different about this.
Upvotes: 2
Views: 1920
Reputation: 1158
You say that you have used this elsewhere. If you have copied GUI elements from some other cell, then you might have forgotten to remove the copied outlet connectors. Check by selecting the elements one by one and check what shows up in the Connections Inspector.
Upvotes: 3