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

标签 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;

}

最佳答案

这很奇怪。

当您说“每隔一次运行”时,您是如何运行该应用程序的?构建并运行?还是只是跑?

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

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

关于iphone - 我的 iPhone 模拟器每次运行时都会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1314599/

相关文章:

iphone - 像我们自己的方法一样调用委托(delegate)方法有没有错

iphone - iPhone App提交并删除二进制文件

java - 什么是内存中的任意地址?

ios - 设置值 :forKey crash with _sigtramp

visual-studio-2013 - 使用 Visual Studio 2013 的 Enterprise Library 6 中的配置工具/控制台抛出 FileNotFoundException

ios - iPhone 应用程序图标背景颜色更改

c# - 如何针对手机(尤其是 iPhone)优化我的网页?

python - python读取大量文件

java - JVM 中的对象表示

ios - 如何在 iOS 中调试 webkit 崩溃日志