我的iPhone模拟器每次运行都会崩溃

我的iPhone模拟器每次运行都会崩溃,iphone,memory-management,crash,ios-simulator,Iphone,Memory Management,Crash,Ios Simulator,该应用程序将运行良好,然后崩溃-字面上每隔一次。看起来崩溃会清理内存,而干净的运行会破坏内存 我认为这与内存分配有关,但我不确定 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"MyStateCell"; static NSString *MyNib = @"Stat

该应用程序将运行良好,然后崩溃-字面上每隔一次。看起来崩溃会清理内存,而干净的运行会破坏内存

我认为这与内存分配有关,但我不确定

- (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;

}这真是太奇怪了

当你说每隔运行一次时,你是如何运行应用程序的?构建并运行?还是就跑

如果是构建并运行,您是否有复制文件或进行任何自定义处理的自定义构建阶段


反向跟踪表明,在NIB加载期间,特别是在设置出口时,is正在崩溃。您是否有可能将错误的对象作为文件的所有者?根据应用程序启动时从文件系统读取的内容,可能会有不同的代码路径?

我没有进行任何自定义处理。我只是加载一个包含一些数据的文本文件。没什么疯狂的事。感谢您的回答B使用您的cellForRowAtIndexPath方法在这里:cellForRowAtIndexPath。我正在使用一个xib来创建tableCellView。它就是这样。我的状态映像单元格xib上的文件所有者类错误。文件的所有者必须是UIViewController,并且其视图必须设置为UITableCellView。UITableViewCell的类是我的自定义StateCell类。所有的IBOutlets都在这门课上失败,并连接到xib。太好了。很高兴你修好了。这类错误在你第一次看到它们的时候感觉就像伏都教一样。。。第30次之后,它们最终变得显而易见。