嗨,我遇到了didSelectRowAtIndexPath問題,我的應用程序在選中某行時出現EXC-BAD-ACCESS錯誤。奇怪的是,我在accessoryButtonTappedForRowWithIndexPath中具有完全相同的代碼片段,並且它正確顯示了詳細信息視圖。這是此方法的代碼。didSelectRowAtIndexPath問題
-(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;
}
請告訴我們應用程序崩潰的發佈源代碼行。並且請張貼堆棧跟蹤。否則,它只是猜測。 – Codo 2011-03-05 14:46:26
發佈的代碼看起來不錯,除了可能的內存泄漏,但不是崩潰的原因。內存泄漏是_childController_實例。您可以使用此方法創建它,並在方法結束時將該變量設置爲_nil_。你應該先釋放它。爲什麼_childController_無論如何都是一個實例變量(而不是本地變量)?由於您始終將其設置爲_nil_,因此可能不會在其他地方使用。 – Codo 2011-03-05 14:48:52
代碼在最後一行失敗後完成。發生錯誤時控制檯中沒有堆棧跟蹤。 – JohnB 2011-03-05 15:24:37