The app will run fine, then crash – literally every other time. It seems like the crash cleans up the memory and clean run corrupts the memory.
I assume it has to do with memory allocation but I am not sure.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyStateCell";
static NSString *MyNib = @"StateCell";
StateCell *cell = (StateCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
UIViewController *c = [[UIViewController alloc] initWithNibName:MyNib bundle:nil];
cell = (StateCell *)c.view;
[c autorelease];
}
// Configure the cell.
NSString *cellAnswerName = [[NSString alloc] initWithFormat:@""];
cellAnswerName = [theQuizArray objectAtIndex:indexPath.row];
int theStatusCode = [[theResultArray objectAtIndex:indexPath.row] intValue];
NSString *statusString;
NSString *pointsWon;
if(theStatusCode == 0){
statusString = [NSString stringWithFormat:@""];
pointsWon = [NSString stringWithFormat:@""];
}else if( theStatusCode == 12){
statusString = [NSString stringWithFormat:@"Wrong"];
pointsWon = [NSString stringWithFormat:@"0"];
}else if(theStatusCode == 11){
statusString = [NSString stringWithFormat:@"Out of time"];
pointsWon = [NSString stringWithFormat:@"0"];
}else{
int elapsedTime = 10 - theStatusCode;
int pointsWonInt = 10 * theStatusCode;
pointsWon = [NSString stringWithFormat:@"%i", pointsWonInt];
if(elapsedTime == 1){
statusString = [NSString stringWithFormat:@"%i second", elapsedTime];
}else{
statusString = [NSString stringWithFormat:@"%i seconds", elapsedTime];
}
}
NSString *imagePath = [[@"State_" stringByAppendingString:cellAnswerName] stringByAppendingString:@".png"];
UIImage *image = [UIImage imageNamed:imagePath];
[[cell stateImage] setImage:image];
[[cell stateName] setText:cellAnswerName];
[[cell stateResult] setText:statusString];
[[cell statePoints] setText:pointsWon];
if([statusString isEqualToString:@"Wrong"])
[[cell stateResult] setTextColor:[UIColor redColor]];
return cell;
}
That is pretty bizarre.
When you say “every other run”, how are you running the app? Build and run? Or just run?
If it is build and run, do you have any custom build phases that copy files or do any custom processing?
The backtrace indicates that is is crashing during NIB loading, specifically when it is setting an outlet. Any chance you have the wrong object as file’s owner? Maybe a different code path depending on what is read from the filesystem at app launch?