简体   繁体   English

如何在Swift中切换不同的ViewControllers或NavigationController?

[英]How to switch between different ViewControllers or NavigationController in Swift?

I just got into Swift programming lately and I have an easy question I can't answer.我最近刚接触 Swift 编程,我有一个简单的问题我无法回答。

I understood that we start putting a ViewController to show something, then if I want to display another view I can use a segue linked to another view.我知道我们开始放置一个 ViewController 来显示一些东西,然后如果我想显示另一个视图,我可以使用链接到另一个视图的 segue。 But I don't like the fact that the view called by the segue doesn't take the full screen.但我不喜欢 segue 调用的视图没有全屏显示这一事实。 It just looks like a pop-up screen.它看起来就像一个弹出屏幕。

So, how could I switch from a ViewController to another ViewController or NavigationController or whatever that keep the fullscreen view.那么,我怎么能从一个 ViewController 切换到另一个 ViewController 或 NavigationController 或任何保持全屏视图的东西。 How could I change my view without passing through a segue and get the following view like a pop-up?我怎样才能在不通过 segue 的情况下更改我的视图并像弹出窗口一样获得以下视图?

Hope my wonder is clear enough to be answered:D希望我的疑问足够清楚,可以得到解答:D

Thanks a lot to the community !!!非常感谢社区!!!

You can make your segue's presentation style as fullscreen.您可以将您的 segue 的演示风格设为全屏。 But if you want to use UINavigationController, first you need to embed your ViewController in UINavigationController(rootViewController: ViewController()).但是如果你想使用UINavigationController,首先你需要在UINavigationController(rootViewController: ViewController())中嵌入你的ViewController。 After that you can navigate to another ViewController using pushViewController method.之后,您可以使用 pushViewController 方法导航到另一个 ViewController。

When you use UINavigationController, it will stack on top of each other.当你使用 UINavigationController 时,它会堆叠在一起。 When you use popViewController, the current ViewController will be popped off from the stack.当你使用 popViewController 时,当前的 ViewController 将从堆栈中弹出。 That's how works in general.这就是一般的工作方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift 4-如何以编程方式从UITabBarController在ViewController之间切换 - Swift 4 - How to switch between ViewControllers from a UITabBarController programmatically swift - 如何在一个 tabBarItem 的两个视图控制器之间切换,并自定义它? - swift - how switch between two viewcontrollers from one tabBarItem , and customize it? 如何在 ViewControllers 之间给不同的 tableViews 相同的动作 [swift] - How to give different tableViews same action between ViewControllers [swift] Swift 3:以编程方式切换ViewController - Swift 3 : Switch ViewControllers programmatically 在与NavigationController捆绑在一起的ViewController之间发送对象 - Sending objects between viewcontrollers that are bundled with navigationcontroller 我在Navigationcontroller中的视图控制器之间切换时发生崩溃? - crashed while i switching between viewcontrollers in navigationcontroller? 在同一个 NavigationController 下的两个 ViewController 之间翻转 - Flip between two ViewControllers under the same NavigationController Swift 4如何在ViewControllers和ContainerViews之间传递数据? - Swift 4 How to pass data between ViewControllers and ContainerViews? 如何在Swift中的多个ViewController之间共享数据 - how to share data between many ViewControllers in Swift swift中如何控制ViewController之间的执行顺序? - How to control the order of execution between ViewControllers in swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM