首页 文章

popViewControllerAnimated不会更新信息iPhone SDK

提问于
浏览
3

当我尝试弹出一个视图控制器时,它不会更新上一个视图的信息 . 示例:我有一个单元格,在View1的标签中显示文本 . 单击单元格时,它转到View2(例如)当我在View2中选择一个选项时,popViewControllerAnimated用于返回View1,但是,我希望现在可以使用View1中的新选项更新标签 .

我的困境是当我弹出View2时,View1中的标签不会更新 . 有任何想法吗?我试过添加[view1 reloadData];在视图弹出之前,但没有运气 .

//VIEW1 the cell that displays the label.
    ringLabel = [[UILabel alloc] initWithFrame: CGRectMake(25, 12.7f, 250, 20)];
    ringLabel.adjustsFontSizeToFitWidth = YES;
    ringLabel.textColor = [UIColor blackColor];
    ringLabel.font = [UIFont systemFontOfSize:17.0];
    ringLabel.backgroundColor = [UIColor clearColor];
    ringLabel.textAlignment = UITextAlignmentLeft;
    ringLabel.tag = 0;
    ringLabel.text = [plistDict objectForKey:@"MYOPTION"];
    [ringLabel setEnabled:YES];
    [cell addSubview: ringLabel];
    [ringLabel release];


//VIEW2 when cell clicked 
    CustomProfileViewController *cpvc = [CustomProfileViewController alloc];
    cpvc.ringtone = [ringList objectAtIndex:indexPath.row];
    [cpvc.tblCustomTable reloadData];
    [self.navigationController popViewControllerAnimated:YES];

3 回答

  • 0

    您将要在第一个视图控制器上覆盖 -viewWillAppear: 并在那里更新标签 . (确保也调用 super ) .

    例:

    - (void)viewWillAppear:(BOOL)animated {
        // This method is called whenever the view is going to appear onscreen.
        // (this includes the first time it appears.)
        ringLabel.text = [plistDict objectForKey:@"MYOPTION"];
        [super viewWillAppear:animated];
    }
    
  • 6

    你的plistDict对象是什么?你如何初始化它?您确定,在第二个视图隐藏后,它包含@“MYOPTION”键的正确值吗?我可以看到,plistDict是你第一个viewController中的一个对象 . 此外,我在代码的最后4行中看不到任何意义 . 它们导致不重新加载数据而是内存泄漏 .

  • 0

    确保你没有丢失dealloc方法中的任何重要内容 . 这让我搞砸了好几个星期 . 我正在释放一个指向我的代表中的变量的变量 .

相关问题