【问题标题】:popViewControllerAnimated doesn't update info iPhone SDKpopViewControllerAnimated 不更新信息 iPhone SDK
【发布时间】:2010-12-25 22:47:24
【问题描述】:

当我尝试弹出视图控制器时,它不会更新前一个视图的信息。示例:我有一个单元格在 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];

【问题讨论】:

    标签: iphone uitableview ios uiview


    【解决方案1】:

    您需要在第一个视图控制器上覆盖 -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];
    }
    

    【讨论】:

    • 试过了,还是不行。我什至尝试在 WillLoad/Didload 中重新加载数据,但没有!只有当我返回根视图控制器然后返回 view1 控制器时,标签才会更新。我不知道为什么它不更新!
    • 验证 viewWillAppear 是否被调用(它是或有问题)并验证 plistDict 是否具有 MYOPTION 键的预期值。这些都可以由一个 NSLog 处理,该 NSLog 显示从 viewWillAppear 调用的字典中的值。
    【解决方案2】:

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

    【讨论】:

    • 这是一个字符串。数据已正确初始化,因为我在其他地方使用了相同的方法。问题是 popViewController,我不确定它是否允许以前的 VC 出于某种原因进行更新。在最后 4 行中,我尝试将 CPVC 的铃声 NSString 设置为我的新数据,它在其他区域有效,只是在弹出视图时无效!有没有其他方法可以在没有“pushViewController”的情况下返回上一个控制器
    • plistDict 是一个字符串??????你试图找到一些关键的价值???我无法想象你的最后 4 行什么时候可以工作。他们没用。正如下面的许多人一样,我建议您在 viewWillAppear 方法中检查您的 plistDict。它会在你的视图控制器弹出后被调用
    【解决方案3】:

    确保你在你的 dealloc 方法中没有丢失任何重要的东西。这让我搞砸了好几个星期。我正在释放一个指向我委托中的变量的变量。

    【讨论】:

      猜你喜欢
      • 2011-05-06
      • 1970-01-01
      • 2010-09-26
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 2023-02-07
      • 1970-01-01
      相关资源
      最近更新 更多