离开导航控制器 [英] Segue Out of Navigation Controller

查看:110
本文介绍了离开导航控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图离开初始视图控制器,然后进入空白视图控制器。这很好,但这会使空白视图控制器也成为导航控制器的一部分,这不是我想要的。我想从视图控制器中删除。



在视图控制器中我尝试将其删除,它会自动弹出,当我在视图中尝试该方法时将出现目标视图控制器, self.navigationController?.topViewController 返回自身,但 self.navigationController?.popViewControllerAnimated(动画)无法使用





转到要导航的课程并添加以下代码

 让storyboard = UIStoryboard(名称:Main,bundle:nil)
// vc是你添加了
//的故事板ID! ...添加要导航到
的ViewController类名称让控制器= storyboard.instantiateViewControllerWithIdentifier(vc)为! ViewController
self.presentViewController(控制器,动画:true,完成:{() - > Void in
})

在您要导航时使用的操作中添加此代码。


I am trying to leave the initial view controller, and go into the blank view controller. That is fine, but that would make the blank view controller also part of the navigation controller, which is not what I want. I want to segue out of the view controller.

In the view controller I try to segue out of, it pops it self, and when I try the method in the view will appear of the target view controller, self.navigationController?.topViewController returns itself, but self.navigationController?.popViewControllerAnimated(animated) doesn't work

解决方案

If you have a navigationController do

self.navigationController?.popViewControllerAnimated(false)

Otherwise do

self.dismissViewControllerAnimated(false, completion: nil)

Update

Go to your Storyboard, select the ViewController you want to navigate to and add a storyboard id. Make sure the click "Use Storyboard ID"

Go to the class you want to navigate from and add the following code

let storyboard = UIStoryboard(name: "Main", bundle: nil)
// vc is the Storyboard ID that you added
// as! ... Add your ViewController class name that you want to navigate to
let controller = storyboard.instantiateViewControllerWithIdentifier("vc") as! ViewController
self.presentViewController(controller, animated: true, completion: { () -> Void in
})

Add this code in the action that you use when you want to navigate.

这篇关于离开导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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