在Storyboard中切换UINavigationController堆栈的最佳实践 [英] Best practice for switching between UINavigationController stacks in Storyboard

查看:70
本文介绍了在Storyboard中切换UINavigationController堆栈的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的故事板中,我们有多个 UINavigationController 堆栈。例如, LoginViewController 堆栈与 SWRevealViewController 堆栈完全分开。

In our storyboard we have multiple UINavigationController stacks. For example, the LoginViewController stack is completely separate from the SWRevealViewController stack.

在它们之间切换的最佳做法是什么?当我按下注销按钮(注销按钮在 SWRevealController 堆栈上)然后尝试呈现LoginViewController堆栈时,我收到如下错误:

What's the best practice for switching between them? When I press the logout button (the logout button is on the SWRevealController stack) and then try to present the LoginViewController stack, I get an error like this:

Warning: Attempt to present LoginViewController on SWRevealViewController whose view is not in the window hierarchy!

即使我专门设置 self.window.rootViewController 到App View的Login View Controller的 UINavigationController ,如下所示:

Even though I'm specifically setting self.window.rootViewController to the Login View Controller's UINavigationController in App Delegate like this:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Spitfire" bundle:nil];
UINavigationController *nav = [storyboard instantiateViewControllerWithIdentifier:@"LoginNavigationController"];
LoginViewController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];

self.window.rootViewController = nav;
[nav presentViewController:loginVC animated:NO completion:nil];    

有没有办法可以解雇当前的 UINavigationController 堆叠并使用新的?或者也许我不应该在我的应用代理中调用此代码?

Is there a way I can "dismiss" the current UINavigationController stack and use a new one? Or maybe I shouldn't be calling this code in my app delegate?

推荐答案

我没有在你的问题之前玩 SWRevealViewController ,所以我的之前的回复更为通用。我已经创建了一个示例应用程序此处,尽可能多地使用尽可能多的导航堆栈;我确定我已经覆盖了你的用例。

I had not played with SWRevealViewController before your question, so my previous response was a little more generic. I've created a sample app here that does its best to throw around as many navigation stacks as possible; I'm sure I've covered your use case.

我会引起你注意的一些事情:

A few things I'll draw your attention to:


  1. 我之前回答的主要流程正好在故事板的中间;这应该有助于确定你的方向。

  1. The "main flow" from my previous answer is right smack in the middle of the storyboard; that should help orient you.

SWRevealViewController.m 可与故事板结合使用非常聪明的黑客这样做,但它的文档是埋没在实施中。我花了一段时间来弄清楚到底发生了什么,但我的示例应用程序说明了用法(两个segues,一个用于front,另一个用于back,可能有三个用于right)。

SWRevealViewController.m can be used in conjunction with Storyboards and has a very clever hack to do so, but the documentation for it is buried in the implementation. It took me a while to figure out what the hell was happening, but my example app illustrates the usage (two segues, one for "front" and the other for "back", could have a third for "right").

应用程序的主流完全换出备用流程。这是按 SWRevealViewController 的设计。您基本上是切换到一个全新的应用程序。

The app's main flow gets completely swapped out for the alternate flow. This is by design of SWRevealViewController. You are essentially switching to an entirely new app.

所有以模式呈现的子流中断流程。

SWRevealViewController 的作者未提供 UIStoryboardSegue 用于替换前视图,后视图和右视图控制器的子类。这实现起来很简单,但我选择在 FHKSettingsViewController 的实现中手动进行交换。

The author of SWRevealViewController has not provided UIStoryboardSegue subclasses for the replacement of front, rear, and right view controllers. This would be trivial to implement, but I've elected to do the swapping manually in FHKSettingsViewController's implementation.

我重复了一些代码并制作了一些极简的课程,以确保我所做的事情是显而易见的。

I repeated code and made dinky classes to make sure what I was doing was obvious.

这篇关于在Storyboard中切换UINavigationController堆栈的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆