【问题标题】:Previous ViewController stays active以前的 ViewController 保持活动状态
【发布时间】:2019-07-22 08:02:57
【问题描述】:

我有一个 ViewController,我通过具有以下功能的 tableviewcell 以编程方式切换到它。

private func switchView(identifier : String){
    DispatchQueue.main.async {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: identifier) as UIViewController
        self.present(vc, animated: true, completion: nil)
     }
}

一段时间后我需要切换回原来的状态,所以我再次用相同的视图调用 switchView。唯一的问题是很多东西在之前的 ViewController 中保持活跃。

如何解除之前的 ViewController 及其所有内容?

【问题讨论】:

  • 当你想转到上一个视图时,只需检查标识符并使​​用 pushviewcontroller 而不是现在。

标签: swift


【解决方案1】:

您是否尝试过在您试图摆脱的 VC 上调用“解雇”?

self.dismiss(animated: true, completion: {
let vc = FirstController()
pvc?.present(vc, animated: true, completion: nil)
})

Found this answer here

【讨论】:

  • 应该注意,这段代码会回到FirstController,然后在自身之上呈现FirstController。导致用户在 viewController 堆栈中有 2x FirstController
  • @Vollan 这不是我想要的。我想从 FirstController 导航回一个新的 Fresh FirstController。
猜你喜欢
  • 2012-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-14
  • 2011-11-22
  • 2011-04-05
相关资源
最近更新 更多