在 xcode6 中的 UINavigationController segues 之间切换?

Switch between UINavigationController segues in xcode6?

我的视图控制器可以呈现 2 个导航视图控制器,每个视图控制器都有自己的视图控制器堆栈:

现在我希望能够随时切换这些导航控制器。我通过新的展示功能展示它们。例如,我深入了解顶部导航控制器的层次结构,我想切换到底部。我可以只调用网络视图控制器吗

UIViewController *rootController = (UIViewController *)[UIApplication sharedApplication].keyWindow.rootViewController;
[rootController performSegueWithIdentifier:@"sessionsNavigationController" sender:nil];

将顶部控制器保留在堆栈上并将底部放在上面,它会取代它们吗?

英语不是我的母语,但如果我不清楚我想要什么,我会尝试提供一些额外的信息。

最好的方法是在 AppDelegate.m

中自己处理切换
UINavigationController* firstNVC;
UINavigationController* secondNVC;
BOOL showingFirst;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Store two local pointers to the Navigation Controllers you want to switch between
    self.firstNVC = [[UIStoryboard storyboardWithName:@"main" bundle:nil] instantiateViewControllerWithIdentifier:@"firstNVC"];
    self.secondNVC = [[UIStoryboard storyboardWithName:@"main" bundle:nil] instantiateViewControllerWithIdentifier:@"secondNVC"];
    //Add yourself to listen for a notification to switch controllers
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(switchViews:)
                                             name:@"switchViews"
                                           object:nil];
    //Set toggle bool
    showingFirst = TRUE;
    //Set first view to show
    self.window.rootViewController = self.firstNVC;
    return YES;
}

- (void)switchViews:(NSNotification *)notification 
{
    //Swap viewcontrollers
    if(showingFirst)
        self.window.rootViewController = self.secondNVC;
    else
        self.window.rootViewController = self.firstNVC;
    //Toggle bool
    showingFirst = !showingFirst;
}

然后在您的应用程序中任何您想要切换控制器的地方,只需使用此行即可post向您的 AppDelegate

发送通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"switchViews" object:self userInfo:nil];

如果您希望用户能够控制切换,Tab Bar Controller 将是您的最佳选择。您可以将每个导航控制器连接到 UITabBarController 中的一个选项卡。这将允许用户随意在顶部和底部导航控制器之间切换。当您切换时,这还将为每个导航控制器保存您在视图控制器堆栈中的位置。