在第二个viewController中的viewDidLoad之后EXC BAD ACCESS

时间:2013-01-26 00:42:38

标签: iphone

HDLogOnViewController将两个变量传递给中的HDDomicileViewController tableview:HDLogOnViewController的didSelectRowAtIndexPath方法。

在HDDomicileViewController的viewDidLoad方法之后,应用程序崩溃并出现EXC BAD ACCESS错误。在HDDomicileViewController中验证变量是正确的。

我已经让Zombies没有帮助了。当我启用Guard Malloc时,应用程序正常运行。在XCode的输出视图中,没有指示导致错误的原因。我在这里研究了许多EXC BAD ACCESS线程,并尝试使用属性而不是实例变量。我使用了四个if语句而不是if else if。执行此操作时,应用程序将只使用一个if语句正常运行,但会崩溃多个。此外,使用四个if语句,我可以注释掉每个语句的语句,它会崩溃,使得问题出现在if条件中。

如何发现导致错误的原因?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *cellLabel = [NSString stringWithString:[[[HDLogOnStore sharedStore] cellTitleLabels] objectAtIndex:[indexPath row]]];

if ([cellLabel isEqualToString:@"Domicile"]) {

    tableViewArray = [[HDLogOnStore sharedStore] domiciles];
    tableViewArrayName = @"domiciles";

    NSLog(@"indexPath row is %i", [indexPath row]);
    NSLog(@"array name is %@", [[[HDLogOnStore sharedStore] cellTitleLabels] objectAtIndex:[indexPath row]]);
}

else if  ([cellLabel isEqualToString:@"Position"]) {

    tableViewArray = [[HDLogOnStore sharedStore] positions];
    tableViewArrayName = @"positions";

    NSLog(@"indexPath row is %i", [indexPath row]);
    NSLog(@"array name is %@", [[[HDLogOnStore sharedStore] cellTitleLabels] objectAtIndex:[indexPath row]]);
}

 else if ([cellLabel isEqualToString:@"BidRound"]) {

    tableViewArray = [[HDLogOnStore sharedStore] bidRounds];
    tableViewArrayName = @"bidRounds";

    NSLog(@"indexPath row is %i", [indexPath row]);
    NSLog(@"array name is %@", [[[HDLogOnStore sharedStore] cellTitleLabels] objectAtIndex:[indexPath row]]);
}

else if ([cellLabel isEqualToString:@"Month"]) {

    tableViewArray = [[HDLogOnStore sharedStore] months];
    tableViewArrayName = @"months";

    NSLog(@"indexPath row is %i", [indexPath row]);
    NSLog(@"array name is %@", [[[HDLogOnStore sharedStore] cellTitleLabels] objectAtIndex:[indexPath row]]);
}

HDDomicileViewController *domicileViewController = [[HDDomicileViewController alloc]init];
[domicileViewController setSelectedArray:tableViewArray];
[domicileViewController setSelectedArrayName:tableViewArrayName];

[self.navigationController pushViewController:domicileViewController animated:YES];

}

1 个答案:

答案 0 :(得分:0)

我开始出现不一致的行为,所以我回到这里阅读更多帖子。

我通过遵循建议来解决问题,以纠正在分析项目后发现的所有错误。我纠正了一些看似无关的错误,例如“在初始化期间永远不会读取存储到'配对'的值”。我不确定这是否直接解决了问题,但在此过程中某个问题消失了。

FYI

应用程序在viewDidLoad方法之后和viewWillAppear方法之前崩溃。一步一步的调试让我得到了我一无所知的机器代码。

- (void)viewDidLoad
{
   [super viewDidLoad];

   NSLog(@"selectedArray count is %i",[selectedArray count]);
   NSLog(@"selectedArray name is %@",selectedArrayName);
   NSLog(@"checkedRowMonth is %i",[[HDLogOnStore sharedStore]checkedRowMonth]);

}

- (void) viewWillAppear:(BOOL)animated
{
   [super viewWillAppear:animated];
}
相关问题