首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在第二个viewController中的viewDidLoad之后出现EXC访问错误

在第二个viewController中的viewDidLoad之后出现EXC访问错误
EN

Stack Overflow用户
提问于 2013-01-26 08:42:38
回答 1查看 499关注 0票数 1

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

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

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

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

代码语言:javascript
复制
- (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];

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-28 00:35:11

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

我按照分析项目后发现的所有错误的建议解决了这个问题。我纠正了一些看似不相关的错误,比如“在初始化期间存储到‘配对’的值永远不会被读取”。我不确定这是否直接解决了问题,但在这个过程中,问题消失了。

仅供参考

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

代码语言:javascript
复制
- (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];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14532556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档