HDLogOnViewController将两个变量传递给表视图中的HDDomicileViewController : HDLogOnViewController的didSelectRowAtIndexPath方法。
在HDDomicileViewController的viewDidLoad方法之后,应用程序崩溃并出现EXC BAD访问错误。在HDDomicileViewController中验证变量是否正确。
我已经在没有帮助的情况下启用了僵尸。当我启用Guard Malloc时,应用程序运行正常。在XCode的输出视图中,没有显示导致错误的原因。我在这里研究了许多EXC错误的访问线程,并尝试使用属性而不是实例变量。我使用了四个if语句,而不是if else if。执行此操作时,应用程序将仅使用一条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];}
发布于 2013-01-28 00:35:11
我开始得到不一致的行为,所以我回到这里阅读更多的帖子。
我按照分析项目后发现的所有错误的建议解决了这个问题。我纠正了一些看似不相关的错误,比如“在初始化期间存储到‘配对’的值永远不会被读取”。我不确定这是否直接解决了问题,但在这个过程中,问题消失了。
仅供参考
该应用程序在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];
}https://stackoverflow.com/questions/14532556
复制相似问题