Swift-创建菜单以从多个位置导航到同一视图控制器

时间:2018-08-22 04:18:43

标签: swift uinavigationcontroller

这是我的代码,用于在我的应用中导航不同的导航控制器。

我有一个模式视图来显示菜单,然后选择导航位置, 这是一个好方法吗?

func circleMenu(_: CircleMenu, buttonDidSelected _: UIButton, atIndex: Int) {

weak var pvc = self.presentingViewController

    if atIndex == 1 {
        self.dismiss(animated: true) {
            let storyboard = UIStoryboard(name: "Experiencia", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "ExperienciaNavigationController")
            pvc?.present(vc, animated: true, completion: nil)
        }

    }

    if atIndex == 2 {
        self.dismiss(animated: true) {
            let storyboard = UIStoryboard(name: "Servicios", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "ServiciosNavigationController")
            pvc?.present(vc, animated: true, completion: nil)
        }
    }

    if atIndex == 3 {
        self.dismiss(animated: true) {
            let storyboard = UIStoryboard(name: "Book", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "DemoViewController")
            pvc?.present(vc, animated: true, completion: nil)
        }
    }
}

然后在其他选定的vc中,我将这段代码返回到root

func back() {
   self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
}

最后一个问题是关于将要关闭的导航控制器...将关闭所有显示的视图吗?以避免内存问题。

我阅读了有关实现协调器模式的信息。但我不知道这种情况是否可以做到 Coordinator pattern or Navigator

0 个答案:

没有答案