【问题标题】:Dismissing 2 viewControllers关闭 2 个视图控制器
【发布时间】:2011-03-24 09:26:58
【问题描述】:

是否可以有效地关闭 2 个视图控制器?

我目前有 3 个 viewController

View1 > 呈现 View2 , View2 > 呈现 View3,然后当在 View3 中触发动作时,我需要返回到 View1 的 Viewcontroller。

在不创建新的 View1 对象的情况下如何做到这一点?

【问题讨论】:

    标签: iphone uiviewcontroller


    【解决方案1】:
    [self.navigationController popToRootViewControllerAnimated:YES];
    

    或者

    int index=[[self.navigtionController viewControllers] indexOfObject:self]-2;
    //make sure index is within the range of the array otherwise it will do bad things.
    UIViewController *vc=[[self.navigationController viewControllers] objectAtIndex:index];
    [self.navigationController popToViewController:vc animated:YES];
    

    可以使用

    【讨论】:

    • 我不使用导航控制器 pushViewControllers。我提出意见。 [self presentModalViewController:vc 动画:YES];
    【解决方案2】:

    由于它们都是模态呈现的,最好的办法可能是将 view2 设置为 view3 的委托,以便 View3 可以调用将关闭 view3 和 view2 的委托方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 2018-11-27
      • 2017-01-06
      • 2011-03-14
      • 2017-02-03
      相关资源
      最近更新 更多