首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >didSelectRowAtIndexPath问题

didSelectRowAtIndexPath问题
EN

Stack Overflow用户
提问于 2011-03-05 22:30:21
回答 3查看 487关注 0票数 0

您好,我有一个didSelectRowAtIndexPath的问题,我的应用程序崩溃与EXC-BAD-ACCESS时,一行被选中。奇怪的是,我在accessoryButtonTappedForRowWithIndexPath中有完全相同的代码段,并且它正确地显示了细节视图。以下是此方法的代码。

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

}
EN

回答 3

Stack Overflow用户

发布于 2011-03-05 23:58:22

请尝试将"childController=nil;“替换为"childController release;”

票数 0
EN

Stack Overflow用户

发布于 2011-03-06 19:37:03

好的,我已经修复了它,但是我不明白为什么它会工作。我在dealloc方法中释放了子控制器,并在viewdidunload中将其设置为nil,问题就解决了。有没有人能解释一下为什么这解决了这个问题?

票数 0
EN

Stack Overflow用户

发布于 2011-03-07 17:24:58

我恳请那些在他们的应用程序中有随机崩溃的人,他们无法解释将NSZombieEnabled添加到构建环境中,有在线指南可以做到这一点,它将为你节省大量的时间!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5204402

复制
相关文章

相似问题

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