didSelectRowAtIndexPath问题

时间:2011-03-05 14:30:21

标签: iphone objective-c

嗨我遇到了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;

}

3 个答案:

答案 0 :(得分:0)

尝试替换“childController = nil;”用“[childController release];”

答案 1 :(得分:0)

好的我已经修好了但是无法理解为什么会这样。我在dealloc方法中释放了子控制器,并在viewdidunload中将其设置为nil,问题得到解决。任何人都可以解释为什么这可以解决这个问题吗?

答案 2 :(得分:0)

我恳求任何在他们的应用程序中随机崩溃的人都无法解释将NSZombieEnabled添加到构建环境中,有指南可以在线提供这样做,它将为您节省大量时间!