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

时间:2009-08-21 23:19:54

标签: iphone memory-management crash ios-simulator

该应用程序将运行正常,然后崩溃 - 几乎每隔一段时间。似乎崩溃会清理内存,干净的运行会破坏内存。

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

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 个答案:

答案 0 :(得分:0)

这很奇怪。

当你说“每隔一次运行”时,你是如何运行该应用程序的?建立并运行?或者只是跑?

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

回溯表示在NIB加载期间崩溃,特别是在设置插座时。您是否有错误的对象作为文件的所有者?可能是一个不同的代码路径,具体取决于在app启动时从文件系统读取的内容?