解雇一堆视图控制器(dismissing a stack of view controllers)

编程入门 行业动态 更新时间:2024-10-27 14:22:08
解雇一堆视图控制器(dismissing a stack of view controllers)

根据文档dismissViewControllerAnimated:completion:将允许您仅通过关闭堆栈底部的控制器来关闭整个视图控制器堆栈。 当我尝试这个时,只有顶级控制器被解雇。

例如,考虑下图,其中控制器A和B都以模态方式呈现。 如果我解雇A,那么A和B 都应该被解雇,但只有 B被解雇!

以下是用户单击B按钮时触发的操作。 根视图控制器解散A(其呈现的控制器),但只有B被解雇!

- (IBAction)dissmissAandB:(id)sender { AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; ViewController *rootViewController = (ViewController *) appDelegate.window.rootViewController; [rootViewController.controllerA dismissViewControllerAnimated:YES completion:^{}];Below }

当准备第一个segue时(即,当呈现A时),设置根视图控制器的controllerA属性。 任何想法为什么这不像宣传的那样工作?

According to the documentation dismissViewControllerAnimated:completion: will allow you to dismiss an entire stack of view controllers by merely dismissing the controller on the bottom of the stack. When I try this, only the top controller is being dismissed.

For example, consider the figure below where controller A and B have both been presented modally. If I dismiss A then both A and B should be dismissed, but only B is being dismissed!

Below is the action that is trigged when the user click on B's button. The root view controller dismisses A (its presented controller), but only B is dismissed!!

- (IBAction)dissmissAandB:(id)sender { AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; ViewController *rootViewController = (ViewController *) appDelegate.window.rootViewController; [rootViewController.controllerA dismissViewControllerAnimated:YES completion:^{}];Below }

The root view controller's controllerA property is set when the first segue is prepared (i.e., when A is presented). Any ideas why this is not working as advertised?

最满意答案

实际上,我发现正确的电话是

[rootViewController dismissViewControllerAnimated:YES completion:^{}];

代替

[rootViewController.controllerA dismissViewControllerAnimated:YES completion:^{}];

该方法的接收器是控制器,其呈现底部控制器而不是底部控制器本身。

Actually, I discovered the correct call is

[rootViewController dismissViewControllerAnimated:YES completion:^{}];

instead of

[rootViewController.controllerA dismissViewControllerAnimated:YES completion:^{}];

The receiver of the method is the controller that presented the bottom controller not the bottom controller itself.

更多推荐

本文发布于:2023-08-01 13:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1360367.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   控制器   dismissing   controllers   view

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!