Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在显示另一个ViewController后,是否有方法关闭当前ViewController?_Ios_Cocoa Touch_Ios7_Uiviewcontroller - Fatal编程技术网

Ios 在显示另一个ViewController后,是否有方法关闭当前ViewController?

Ios 在显示另一个ViewController后,是否有方法关闭当前ViewController?,ios,cocoa-touch,ios7,uiviewcontroller,Ios,Cocoa Touch,Ios7,Uiviewcontroller,在寻找答案一段时间后,我不得不承认我对这个案例相当困惑 在我的工作中,我被要求做一些非常具体的事情: 我必须在以前的UIViewController上显示UIViewController,实际上,当前的ViewController在第二个出现之前会自动关闭。这给了整件事一个有趣的动画,一个ViewController下降,然后另一个从底部上升。但是它不是真正的“专业版”,我们可以在动画中看到场景背后的rootViewController 因此,我必须明确指出,没有NavigationContro

在寻找答案一段时间后,我不得不承认我对这个案例相当困惑

在我的工作中,我被要求做一些非常具体的事情:

我必须在以前的UIViewController上显示UIViewController,实际上,当前的ViewController在第二个出现之前会自动关闭。这给了整件事一个有趣的动画,一个ViewController下降,然后另一个从底部上升。但是它不是真正的“专业版”,我们可以在动画中看到场景背后的rootViewController

因此,我必须明确指出,没有NavigationController,在我看来,这会使这变得容易得多,因此我不得不使用两个UIViewController来实现这一点,这是我的实际代码:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
        UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"userViewController"];
        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:controller animated:YES completion:^{
            [self dismissViewControllerAnimated:YES completion:nil];
}];     
它是在按下按钮后立即调用的,所以我认为实际的ViewController viewDidLoad或viewDidAppear没有问题

但每次运行此代码时,都会出现以下错误:

[1163:17641] Warning: Attempt to present <UserViewController: 0x7b0f0a00> on <EIHomeViewController: 0x7b0d2a00> whose view is not in the window hierarchy!
[1163:17641]警告:试图显示其视图不在窗口层次结构中的对象!
我真的不知道我如何能够保持对当前UIViewController的跟踪,以便在下一个ViewController视图中关闭它。我似乎要确保屏幕上不会出现“黑屏”

提前感谢您的帮助

请尝试以下代码:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"userViewController"];
[self dismissViewControllerAnimated:NO completion:^{
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:controller animated:NO completion:nil];
}];

我以前有相同的代码作为例外,解散是动画,总是有这个“黑”之间的两个viewController,加上我没有更多的“上升”动画。但是,这在很大程度上减少了延误。但我正在搜索允许我在另一个视图上添加ViewController的内容,以便在新ViewController ViewDid出现后关闭另一个视图:但是,如果您从当前vc中呈现下一个vc,您将拥有一个堆栈,如:root->current->next。如果现在在当前(next的presentingViewController)上调用
dismissViewControllerAnimated
,next也将消失。根用户是否没有调用next的选项?像是从堆栈中进行的黑客攻击,还是通过另一层使其出现在屏幕顶部?