【问题标题】:How to remove old ViewControllers from stack如何从堆栈中删除旧的 ViewController
【发布时间】:2015-10-27 12:43:52
【问题描述】:

我想知道如何从堆栈中删除我的旧 VC?

当我启动我的应用程序时,标题中有一个汉堡图标/菜单按钮。

我想要做的是当用户登录我的应用程序时,我想将 VC/Account 页面设置为根视图,以便在查看检查器时看不到底层 VC。

所以或多或少我想在帐户页面的标题中添加一个菜单按钮,而不是返回按钮。

我已经尝试过了,但我无法让它工作:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let yourViewController: ViewController = storyboard.instantiateViewControllerWithIdentifier("respectiveIdentifier") as! ViewController

let navigationController = self.window?.rootViewController as! UINavigationController
navigationController.setViewControllers([yourViewController], animated: true)

【问题讨论】:

  • 你把代码放在哪里了?
  • @Mr.T 在我要创建根 VC 的最后一个 VC 之前的 VC 中
  • 你能澄清一下你想从导航堆栈或应用程序内存堆栈中删除 VC 吗?
  • @Mr.T 有什么区别?我想我想重置我的导航堆栈。使帐户页面成为新的根页面
  • 这个问题可能会有所帮助。 stackoverflow.com/questions/15774003/…

标签: ios iphone xcode swift


【解决方案1】:

我认为你可以使用:

navigationController!.viewControllers.removeAtIndex((navigationController?.viewControllers.count)! - 2)

在加载新控制器后使用它,因此这基本上会删除堆栈中最后一个控制器之前的控制器。如果您在实施它时遇到任何问题,请告诉我。

【讨论】:

    猜你喜欢
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 2016-09-02
    相关资源
    最近更新 更多