0
votes

I have seen a couple questions similar to mine, but none of the answers have worked for me so far.

I have a TabBarController connected to 3 NavigationControllers. Each NavigationController has a custom ViewController. See the screenshot below. One of these ViewControllers has a TableView. I have a cancel button that exits this view by selecting another selectedIndex in an IBAction, which is located in the custom class of this ViewController There are textfields in each cell that the user can enter text in. However, I would like this cancel button to reset the ViewController so that the TableView and everything else in the controller will be reset to their original states. How do I do this?

enter image description here

@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
    }

I have seen answers that said to use "popToRootViewController" or "popViewController" on my NavigationControllers, but none of these have worked, probably because there's only one ViewController in each NavigationController.

1

1 Answers

1
votes

You can try ( after setting storyboard identifier to the rootVC of that navigation )

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

to restart that currentVC