【问题标题】:Dismiss ViewController opened from SideMenu关闭从 SideMenu 打开的 ViewController
【发布时间】:2019-05-04 03:51:45
【问题描述】:

我有一个嵌入在导航堆栈中的带有 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】:

    搜索了一段时间后,我仍然找不到问题的根源,所以我选择了解决方法:

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

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

    【讨论】:

      猜你喜欢
      • 2017-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-24
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多