以编程方式构建/导航导航控制器
之前:
我的应用程序基于独立的视图控制器。我可以通过替换应用程序委托上的根视图控制器来从一种切换到另一种:
ade.window.rootViewController = newController;
...并且到目前为止一切正常。
明天:
我们必须在我们的应用程序中添加一个基于 NavigationController 的部分,这将帮助用户导航我们的:
Brands =>型号名称 =>颜色
因此,用户将选择一种颜色,然后单击一个按钮:现在我将切换到另一个 UIViewController(称之为“pippo”),它实际上位于导航层次结构之外(我无法将其推送到导航控制器中)几种方法,我被迫这样做!)。
我想要的是从“pippo”回到我的“彩色”屏幕。因此,我正在寻找一种以编程方式“导航”我恢复的导航控制器的方法,我的意思是:
我恢复我的导航控制器
现在我在品牌上,但我不希望我的用户在这里,我想向他们展示他们上次使用的颜色(我将其保存在首选项中)
如何模拟选择已知品牌和型号?
多谢。
Before:
My App is based on indepent view controllers. I can switch from one to another by replacing the root view controller on the application delegate:
ade.window.rootViewController = newController;
... and all worked right, till now.
Tomorrow:
we have to add a NavigationController-based part of our App, which will help the users navigate through our:
Brands => Model Names => Colors
So, the user will choose a color, then click a button: now I will switch to another UIViewController (call it "pippo"), which actually resides outside that navigation hierarchy (I can't push it in the nav-controller for several methods, I'm forced doing so!).
What I want is to get back to my "Color" screen, from "pippo". So, I'm looking for a way to programmatically "navigate" the navigation controller I restore, I mean:
I restore my navigation controller
now I'm on Brands, but I don't want my users to be here, I want to show them the last color they was on (I saved it in the preferences)
how can I simulate the selection of a known brand and model?
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在应用程序委托的
applicationDidFinishLoading
中:这将实例化导航控制器并将其作为视图添加到窗口中。
现在,在您的 rootViewController 类(假设它称为 FirstViewController )中,您可以执行以下操作:
在您的 SecondViewController 中,您可以使用以下命令向后导航堆栈:
所以对您来说,它会go:
在应用程序委托中设置导航控制器,并将
Brand
作为根视图控制器用户选择他们的品牌,然后您
pushViewController:animated:
Model
视图控制器。然后用户选择他们的模型,然后您pushViewController:animated:
Color
视图控制器。类似地,用户选择一种颜色,然后您按下Pippo
视图控制器。现在,如果用户按回键(或者调用popViewControllerAnimated:
),它将返回到Color
视图控制器,其状态与用户离开它时的状态相同Pippo
控制器。In
applicationDidFinishLoading
in App delegate:That will instantiate the navigation controller and add it to the window as a view.
Now, in your rootViewController class (lets say its called
FirstViewController
) you can do this:And in your
SecondViewController
you can navigate back through the stack using:So for you it would go:
Set up navigation controller in the app delegate with
Brand
as the root view controllerUser chooses their brand and you
pushViewController:animated:
theModel
view controller. Then the user chooses their model and youpushViewController:animated:
theColor
view controller. Similarly the user chooses a color and you push thePippo
view controller. Now, if the user presses back (or you callpopViewControllerAnimated:
) it will go back to theColor
view controller in the same state as when the user left it to go to thePippo
controller.在AppDelegate.m类中编写以下代码
Write the following code in AppDelegate.m Class