OGeek|极客世界-中国程序员成长平台

标题: iOS:popToRootViewController 用于 presentViewControllers 架构 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 19:58
标题: iOS:popToRootViewController 用于 presentViewControllers 架构

我知道,如果我的项目中有 navigationController,我可以使用 popToRootViewController,但我的整个项目是基于 presentViewControllers 的,并且有一个场景是我要导航到多个级别。如果只有一个级别,我可以通过关闭当前 View Controller 返回 Root View Controller ,但是当我下降到多个级别时,我无法弄清楚如何导航回 Root View Controller 。有人可以在这里给我建议吗?

我尝试使用以下代码,但我的应用程序崩溃了!

- (IBAction)mainMenuButtonPressedid)sender {
    MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    [self presentModalViewController:delegate.window.rootViewController animated:YES];
}

谢谢。



Best Answer-推荐答案


如果我理解正确,那么您将展示几个模态视图 Controller 并希望回到 Root View Controller 。如果这是正确的,那么下面的代码应该适合你:

- (IBAction)mainMenuButtonPressedid)sender {
    MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
    [delegate.window.rootViewController dismissModalViewControllerAnimated:YES];
}

关于iOS:popToRootViewController 用于 presentViewControllers 架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9913147/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4