如何返回导航堆栈? [英] How to go back in the navigation stack?

查看:61
本文介绍了如何返回导航堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序具有7个后续视图控制器:VC1-VC7
在我的导航栏中,我有一个返回按钮,其中包含to动作:点击和longPressed.当在任何VC中长时间按下backButton时,应用程序都应转到VC2并显示它,就像用户从VC1转到VC2一样,特别是:轻按了向后右键.

My app has 7 subsequent view controllers: VC1 - VC7
In my navigation bar I have a back button with to actions: tapped and longPressed. When the backButton gets pressed long in any VC, the app should go to VC2 and present it as if the user went from VC1 to VC2, specifically: with the right back button tapped action.

这是我的UILongPressGestureRecognizer代码:

This is my code for UILongPressGestureRecognizer:

func longPressAction(gestureRecognizer: UIGestureRecognizer) {

    if (gestureRecognizer.state == UIGestureRecognizerState.Ended) {

        println("Long press ended")

    } else if (gestureRecognizer.state == UIGestureRecognizerState.Began) {

        println("Long press detected")

        let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
        let vc: ViewController2 = mainStoryboard.instantiateViewControllerWithIdentifier("vc2") as! ViewController2
        navigationController?.pushViewController(vc, animated: true)

    }

}

如何返回导航堆栈中的正确位置?

How can I go back to the right place in the navigation stack ?

推荐答案

您可以在导航控制器中设置视图控制器数组:

You can set your array of View Controllers in the Navigation Controller:

let viewControllersArray = [VC1,VC2]
self.navigationController.setViewControllers(viewControllersArray, animated: true)

编辑

在您的方案中

else if (gestureRecognizer.state == UIGestureRecognizerState.Began) {

    println("Long press detected")

    let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
    let vc1: ViewController1 = mainStoryboard.instantiateViewControllerWithIdentifier("vc1") as! ViewController1
    let vc2: ViewController2 = mainStoryboard.instantiateViewControllerWithIdentifier("vc2") as! ViewController2
    let VCArray = [vc1,vc2]
    self.navigationController.setViewControllers(VCArray, animated: true)
}

这篇关于如何返回导航堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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