从侧面菜单打开“关闭视图控制器”

问题描述 投票:1回答:1

我有一个小应用程序,有5个屏幕嵌入导航堆栈,我不能解雇UIViewController

我在我的项目中使用SideMenu来呈现它的最后一个UIViewController,这是侧面菜​​单的代码配置:

SideMenuManager.default.menuPushStyle = .replace
SideMenuManager.default.menuPresentMode = .menuSlideIn

以及我如何呈现VC的方式:

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier == "menuToSavedQuotes" {
        _ = segue.destination as? SavedQuotesViewController
    }
}

然后:self.performSegue(withIdentifier: "menuToSavedQuotes", sender: self)

它工作得很好,但是当我把行动解雇时 - 这不起作用。我在我的应用程序中没有使用导航栏,这就是为什么我创建按钮并尝试解除它但失败了。

我尝试的是:

self.navigationController?.popViewController(animated: true) self.dismiss(animated: true, completion: nil)

但这一切都没有奏效。我现在拥有的仍然没有工作的是:

override func viewDidLoad() {
    super.viewDidLoad()
    output?.viewIsReady()
    setupNavigationStack()
}

@IBAction func didPressClose(_ sender: UIButton) {
    print("Here")
    self.navigationController?.popViewController(animated: true)
    //self.dismiss(animated: true, completion: nil)
}

func setupNavigationStack() {
    if let root = UIApplication.shared.keyWindow?.rootViewController as? StartingPageViewController {
        let navigation = root.childViewControllers[0] as! UINavigationController

        let vc1 = self.storyboard!.instantiateViewController(withIdentifier: "StartingPage")
        let vc2 = self.storyboard!.instantiateViewController(withIdentifier: "StartTrial")
        let vc3 = self.storyboard!.instantiateViewController(withIdentifier: "ScheduleNotifications")
        let vc4 = self.storyboard!.instantiateViewController(withIdentifier: "AllQuotes")
        let vc5 = self.storyboard!.instantiateViewController(withIdentifier: "SavedQuotes")

        navigation.setViewControllers([vc1, vc2, vc3, vc4, vc5], animated: true)
    }
}

作为临时解决方案,我的关闭按钮只是打开以前的UIViewController,但这不是一个好习惯。

将不胜感激任何帮助!

谢谢!

ios swift uiviewcontroller segue dismiss
1个回答
1
投票

搜索了一段时间后,我仍无法找到问题的根源,所以我坚持使用解决方法:

关闭按钮只是打开以前的UIViewController但这不是一个好习惯。

在我的情况下,应用程序只有3个屏幕,这很好,但如果谈论更大的应用程序,不推荐这样的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.