i am using navigationController (push and pop) but in a special case i have to show the next viewcontroller using modal segue , and when i dismiss that modal i want to pop the last viewController in the navigationController and then push a new one to appear after dismissing the modal one , how can i access the navigationController that is full of viewControllers from a modal viewController i can send in the last element in navigationController as self in prepareForSegue for the modal but i am asking if there is another way , sorry my questions are always complicated
This will work if your navigationController is the rootViewController
if let navigationController = UIApplication.sharedApplication().keyWindow?.rootViewController as? UINavigationController {
}
Swift 4 answer:
if let navigationController = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController {
//Do something
}
Sounds like a job for delegation or notifications, depending on how you want to go about it. In either case—your navigationController
can either be notified to perform the segue at the right time, or accessed and instructed to do so as a delegate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With