[ios] Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy

Sadly, the accepted solution did not work for my case. I was trying to navigate to a new View Controller right after unwind from another View Controller.

I found a solution by using a flag to indicate which unwind segue was called.

@IBAction func unwindFromAuthenticationWithSegue(segue: UIStoryboardSegue) {
    self.shouldSegueToMainTabBar = true
}

@IBAction func unwindFromForgetPasswordWithSegue(segue: UIStoryboardSegue) {
    self.shouldSegueToLogin = true
}

Then present the wanted VC with present(_ viewControllerToPresent: UIViewController)

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    if self.shouldSegueToMainTabBar {
        let mainTabBarController = storyboard.instantiateViewController(withIdentifier: "mainTabBarVC") as! MainTabBarController
        self.present(mainTabBarController, animated: true)
        self.shouldSegueToMainTabBar = false
    }
    if self.shouldSegueToLogin {
        let loginController = storyboard.instantiateViewController(withIdentifier: "loginVC") as! LogInViewController
        self.present(loginController, animated: true)
        self.shouldSegueToLogin = false
    }
}

Basically, the above code will let me catch the unwind from login/SignUp VC and navigate to the dashboard, or catch the unwind action from forget password VC and navigate to the login page.

Examples related to ios

Adding a UISegmentedControl to UITableView Crop image to specified size and picture location Undefined Symbols error when integrating Apptentive iOS SDK via Cocoapods Keep placeholder text in UITextField on input in IOS Accessing AppDelegate from framework? Autoresize View When SubViews are Added Warp \ bend effect on a UIView? Speech input for visually impaired users without the need to tap the screen make UITableViewCell selectable only while editing Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

Examples related to cocoa-touch

Include of non-modular header inside framework module Move textfield when keyboard appears swift Create space at the beginning of a UITextField Navigation bar with UIImage for title Generate a UUID on iOS from Swift How do I write a custom init for a UIView subclass in Swift? creating custom tableview cells in swift How would I create a UIAlertView in Swift? Get current NSDate in timestamp format How do you add an in-app purchase to an iOS application?

Examples related to ios6

ios simulator: how to close an app Is it possible to install iOS 6 SDK on Xcode 5? How to change navigation bar color in iOS 7 or 6? Detect if the app was launched/opened from a push notification The operation couldn’t be completed. (com.facebook.sdk error 2.) ios6 Evenly space multiple views within a container view how to fix the issue "Command /bin/sh failed with exit code 1" in iphone Setting font on NSAttributedString on UITextView disregards line spacing How do I animate constraint changes? What are Unwind segues for and how do you use them?

Examples related to views

Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy How to find which views are using a certain table in SQL Server (2008)? View's SELECT contains a subquery in the FROM clause What is the difference between a stored procedure and a view? Android: How to get a custom View's height and width? How to create EditText with rounded corners? Can we pass parameters to a view in SQL? In Oracle, is it possible to INSERT or UPDATE a record through a view? Display a view from another controller in ASP.NET MVC What is a View in Oracle?

Examples related to hierarchy

Warning: Attempt to present * on * whose view is not in the window hierarchy - swift Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy Getting activity from context in android How to view hierarchical package structure in Eclipse package explorer