NC / VC1 -present modally- NC2 / VC2 (embed in) - VC3 pop to VC1
I am trying to pop current view controller to the first view controller from another navigation controller.
I couldn't find a way. Anyone knows how to achieve?
NC / VC1 -present modally- NC2 / VC2 (embed in) - VC3 pop to VC1
I am trying to pop current view controller to the first view controller from another navigation controller.
I couldn't find a way. Anyone knows how to achieve?
First in VC1 Class declare this method
class VC1: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func unwindtoVC1(segue: UIStoryboardSegue) {
}
}
Then See Image to create unwind segue
after that in your VC3 class
class VC3: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func didCloseTap(_ sender: Any) {
self.performSegue(withIdentifier: "segueToVC1", sender: nil)
}
}
We need more details about View Controllers hierarchy and how the navigations is done exactly.
Note that unless the other view controller (that you want to show up after you pop current view controller) is not current yet on the hierarchy - there will be problems.
I advice to use a Coordinator Object (which is not a view controller, inherits from NSObject). Make it be the one that decides what view controller should popup and what to show next.
The coordinator needs a reference to App Delegate's window property, in order to set its rootViewController property as needed. All view controllers have to also delegate to the coordinator to notify it about Close / Add / Save events etc.
Watch this presentation https://vimeo.com/144116310 and note that this is a more advanced pattern then what you'll find in Apple's documentation. The idea is that View Controllers should not present other view controllers or know about other view controllers' existence at all... unless it's a Container View Controller, such as UINavigationController, UITabBarController, subclasses of those or custom ones.