【问题标题】:Muiltple Modal UIViewControllers | Dismiss Top Modal UIViewController Only多模态 UIViewControllers |仅关闭顶部模态 UIViewController
【发布时间】:2014-02-06 11:17:20
【问题描述】:

我的UIViewController 堆栈如下所示:

+------ UIViewController_C (presented)
+---- UIViewController_B (presented)
+-- UIViewController_A (pushed)

当我在 UIViewController_C 上调用 -dismissViewController:animated 时,UINavigationControllerboth UIViewController_CUIViewController_B 一起解雇,根据文档,_C 上带有动画,@ 上没有动画987654329@.

解除_C 的最合规方式是什么?

【问题讨论】:

  • 请分享您的代码。在一般情况下它应该可以工作。
  • - 找到了解决方案;将在 8 小时后添加,因为我的表现不佳,我无法写出来。
  • 谢谢@malex - 超级亲切;我和你的思路大致相同,我会尽快分享(T-4 小时)。

标签: ios objective-c uiviewcontroller uinavigationcontroller modalviewcontroller


【解决方案1】:

尝试如下

推送到 UIViewController_A 后,呈现 UIViewController_B 如下代码。

UIViewController_B *bbp=[[UIViewController_B alloc]initWithNibName:@"UIViewController_B" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
passcodeNavigationController.navigationBar.hidden=YES;
[self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];

现在从 UIViewController_B 尝试在 UIViewController_C 中呈现如下代码。

    UIViewController_C *bbp=[[UIViewController_C alloc]initWithNibName:@"UIViewController_C" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
passcodeNavigationController.navigationBar.hidden=YES;
[self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];

视图控制器的每个后退按钮上的最后和最后一件事写在下面的代码行。

[self dismissModalViewControllerAnimated:YES];

如果您需要比下面评论更多的帮助。

【讨论】:

    【解决方案2】:

    一种解决方案:

    UIViewControllers 模态显示不一定是deallocated on -dismissViewController:animated

    这意味着通过将UIViewController_A 的引用通过_B 传递给_C,您可以通过UIViewController_A 分别为UIViewControllers 调用-presentViewController:animated-dismissViewController:animated

    代码:

    1. UIViewController_B

    - (void) showUIViewController_C {
    
        [self dismissViewControllerAnimated:TRUE completion:^{
            UIViewController_C *controller_C = [[UIViewController_C alloc] init];
            controller_C.parentController = self;
            [self.parentController controller_C animated:TRUE completion:nil];
        }];
    }
    

    2。 UIViewController_C

    - (void) dismissUIViewController_C {
    
        [self dismissViewControllerAnimated:TRUE completion:^{
            [self.parentController.parentController presentViewController:self.parentController animated:TRUE completion:nil];
        }];
    }
    

    我在哪里使用*parentController 作为堆栈上您之前的@​​987654334@ 可能是的任何类的命名约定。

    它短暂地回到UIViewController_A,因为我在完成块中调用-dismiss-present,尽管这实际上看起来很有趣。

    【讨论】:

      猜你喜欢
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-08
      • 2021-06-05
      相关资源
      最近更新 更多