代码之家  ›  专栏  ›  技术社区  ›  Bryan

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

  •  0
  • Bryan  · 技术社区  · 16 年前

    应用程序会运行良好,然后崩溃-实际上每隔一次。似乎崩溃会清除内存,而干净的运行会损坏内存。

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

    alt text

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

    }

    1 回复  |  直到 14 年前
        1
  •  0
  •   bbum    16 年前

    这很奇怪。

    当你说“每隔一次跑步”时,你是如何运行应用程序的?建立和运行?还是跑?

    如果它是构建和运行的,您有复制文件的任何自定义构建阶段吗,或者执行任何自定义处理?

    回溯表明在NIB加载过程中发生崩溃,特别是在设置出口时。你有没有可能把错误的对象作为文件的所有者?根据应用程序启动时从文件系统中读取的内容,可能有不同的代码路径?