如何在iOS上的视图之间切换 [英] How to switch between Views on iOS

查看:60
本文介绍了如何在iOS上的视图之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于iOS世界我是一个新手,由于我来自基于活动的Android世界,所以我对iOS如何管理视图之间的过渡有些困惑.

i am pretty new to the iOS world and since I'm coming from the Activity-based world of Android I'm a little bit confused with how iOS manages transitions between Views.

我已经创建了一个UIViewController,它可以全屏显示一个Login表单(这是针对iPad的应用程序).成功登录后,我想切换到另一个视图并使用UISplitViewController.为了能够从我的初始控制器推送到第二个控制器(也是UIViewController),我已经添加了一个UINavigationController,其中第一个控制器为根.

I already created a UIViewController which displays a Login form in full screen (It's an app targeted for the iPad). After a successful login I want to switch to another View and utilize a UISplitViewController. To be able to push from my initial controller to the second (which is also a UIViewController) I've already added an UINavigationController with my first controller being the root.

我已经将UISplitViewController添加到第二个UIViewController的xib中. Xcode以前曾抱怨我的第二个UIViewController没有设置视图出口,因此我基本上将其盲目地设置为UISplitViewController中的detailView.

I've added the UISplitViewController to the xib of my second UIViewController. Xcode previously complained that my second UIViewController didn't have the view outlet set, so I basically blindly set that to the detailView within my UISplitViewController.

结果是第一个UIViewController确实被推开了,但是我没有看到UISplitViewController出现,但是我在视图出口中设置了DetailView.

The result is that the first UIViewController gets indeed pushed away but I don't get the UISplitViewController to show up but the DetailView I have set in the view outlet.

我错过了什么吗?首先显示全屏(没什么花哨,没有多余的装饰)UISplitViewController,然后推到UISplitViewController,有什么必要?我以前的尝试涉及到新的Storyboard功能,但结果却更加令人困惑(即涉及了太多的魔术).也许我只是错了一些iOS的UI范例.

Did I miss something? What is necessary to first display a full screen (nothing fancy, no frills) UISplitViewController and then push over to UISplitViewController? My previous attempts involed the new Storyboard feature but that turned out to be even more confusing (ie. too much magic involved). Maybe I just got some of the UI paradigms of iOS wrong.

推荐答案

您可能想以UINavigationController作为根视图控制器开始. UINavigationController的init方法将另一个视图控制器作为参数(也称为根ViewController),该参数可以是当前用作应用程序的根视图控制器的视图控制器.然后,它将显示在导航控制器中.

You probably want to start with a UINavigationController as your root view controller. UINavigationController's init method takes another view controller as a parameter (confusingly also called a root ViewController) which can be the view controller that you are currently using as the root view controller for your application. That will then be displayed within the navigation controller.

将视图控制器放置在导航控制器中后,可以调用[self.navigationController pushViewController:x]以显示新的视图控制器,然后调用[self.navigationController popViewController]再次返回.如果您不希望导航栏位于顶部,则可以将其设置为隐藏.

Once you've put your view controller inside a navigation controller, you can call [self.navigationController pushViewController:x] to display a new view controller, and [self.navigationController popViewController] to go back again. If you don't want the navigation bar at the top, you can set it to hidden.

或者,您可以通过调用[self presentModalViewController:x]进行显示,从而从另一个视图控制器中显示全屏视图控制器.

Alternatively, you can display a full-screen view controller from within another view controller by calling [self presentModalViewController:x] to show it.

这篇关于如何在iOS上的视图之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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