您好,我有一个didSelectRowAtIndexPath的问题,我的应用程序崩溃与EXC-BAD-ACCESS时,一行被选中。奇怪的是,我在accessoryButtonTappedForRowWithIndexPath中有完全相同的代码段,并且它正确地显示了细节视图。以下是此方法的代码。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
if(childController == nil)
{
childController = [[ScoreCardDetailViewController alloc]initWithNibName:@"ScoreCardDetailView" bundle:nil];
}
ScoreCard *selectedScoreCard = [self.list objectAtIndex:row];
if([self checkPlusMinus:selectedScoreCard.score]==0||[self checkPlusMinus:selectedScoreCard.score]==1)
{
childController.title = [NSString stringWithFormat:@"%@ +%d",selectedScoreCard.course.courseName, selectedScoreCard.score];
childController.selectedScoreCard = selectedScoreCard;
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];
[[self navigationItem] setBackBarButtonItem: newBackButton];
[newBackButton release];
[self.navigationController pushViewController:childController animated:YES];
}
else
{
childController.title = [NSString stringWithFormat:@"%@ %d",selectedScoreCard.course.courseName, selectedScoreCard.score];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];
[[self navigationItem] setBackBarButtonItem: newBackButton];
[newBackButton release];
childController.selectedScoreCard = selectedScoreCard;
[self.navigationController pushViewController:childController animated:YES];
}
childController=nil;
}发布于 2011-03-05 23:58:22
请尝试将"childController=nil;“替换为"childController release;”
发布于 2011-03-06 19:37:03
好的,我已经修复了它,但是我不明白为什么它会工作。我在dealloc方法中释放了子控制器,并在viewdidunload中将其设置为nil,问题就解决了。有没有人能解释一下为什么这解决了这个问题?
发布于 2011-03-07 17:24:58
我恳请那些在他们的应用程序中有随机崩溃的人,他们无法解释将NSZombieEnabled添加到构建环境中,有在线指南可以做到这一点,它将为你节省大量的时间!
https://stackoverflow.com/questions/5204402
复制相似问题