【问题标题】:How to reset UIViewController inside TabBarController如何在 TabBarController 中重置 UIViewController
【发布时间】:2018-12-28 16:43:16
【问题描述】:

我看到了几个与我类似的问题,但到目前为止,没有一个答案对我有用。

我有一个 TabBarController 连接到 3 个 NavigationControllers。每个 NavigationController 都有一个自定义 ViewController。请参阅下面的屏幕截图。 其中一个 ViewController 有一个 TableView。我有一个取消按钮,它通过在 IBAction 中选择另一个 selectedIndex 来退出此视图,该按钮位于此 ViewController 的自定义类中。每个单元格中都有文本字段,用户可以在其中输入文本。 但是,我希望这个取消按钮可以重置 ViewController,以便 TableView 和控制器中的所有其他内容都将重置为其原始状态。我该怎么做?

@IBAction func cancel(_ sender: Any) {
        let index = (self.tabBarController as! MainTabBarController).previouslySelectedIndex!
        animateToTab(tabBarController: self.tabBarController!, to: self.tabBarController!.viewControllers![index])
        self.tabBarController?.selectedIndex = index
    }

我看到有人回答说在我的 NavigationControllers 上使用“popToRootViewController”或“popViewController”,但这些都不起作用,可能是因为每个 NavigationController 中只有一个 ViewController。

【问题讨论】:

    标签: ios swift uiviewcontroller uinavigationcontroller


    【解决方案1】:

    您可以尝试(在将故事板标识符设置为该导航的 rootVC 之后)

    let vc = storyboard!.instantiateViewController(withIdentifier:"CancelVC") as! CancelVC  
    self.navigationController?.setViewControllers([vc],animated:true)
    

    重启当前的VC

    【讨论】:

      猜你喜欢
      • 2015-07-14
      • 2017-07-16
      • 2013-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多