根据文档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.
更多推荐
发布评论