iOS Can't dismiss view controller

ios 13
iphone
iphone 11
iphone se
ios 13 compatibility
ios 12
ios 14
ios 13 iphone 6

I have issue with my app. Scenario is simple, after successfully account creation i wan't to dismiss current page or navigate to login page. My storyboard looks like this:

After successful account creation i having a popup with some info about it's ok, we send you verification email and after this popup i want to go to the page second from left - it's my main application page (now called "View Controller").

I tried dismiss window, but i have no effect there, it can only dismiss my popup window. When i trying to redirect then i have issue with back button when is pressed,it lead to Sign Up page. There is some code:

// Create new user and send verification email

        Auth.auth().createUser(withEmail: userEmail, password: userPassword) { user, error in if error == nil && user != nil {
            self.sendVerificationMail();
            self.displayAlertMessage(alertTitle: "Success", alertMessage: "Your account created successfully. We send you a verification email.");

            // Redirect to View Controller

            } else {
            self.displayAlertMessage(alertTitle: "Unhandled error", alertMessage: "Undefined error #SignUpViewController_0002");
            }
        }

...

func displayAlertMessage(alertTitle: String, alertMessage:String, alertRedirection:String = ""){
        let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert);

        let okAction = UIAlertAction(title:"Ok", style: UIAlertAction.Style.default, handler: nil);

        alert.addAction(okAction);

        self.present(alert, animated:true, completion:nil);
    }

If i add this:

self.view.window!.rootViewController?.dismiss(animated: false, completion: nil)

After alert, it close only alert, before alert, it do nothing ( same as dismiss).

To dismiss and pop to main view you can use alert button action handler.

alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: { (action) in

            self.dismiss(animated: true, completion: {
                self.navigationController?.popToRootViewController(animated: true)
            })
        }))

Or you can use the navigation to specific view controller using below lines.

for viewController in self.navigationController!.viewControllers {
            if viewController.isKind(of: <Your_Main_ViewController_Class_Name>.self) {
                self.navigationController?.popToViewController(viewController, animated: true)
                break
            }
        }

Your_Main_ViewController_Class_Name is the view controller that within your navigation controller stack to which you need to navigate. (ie) main view

To blindly navigate to main view once alert popup displayed, you can use completion handler while present the alert.

self.present(alert, animated: true, completion: {
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
                self.navigationController?.popToRootViewController(animated: true)
            }
        })

iOS 13 - Features, All without having to go to another screen. Enhanced Siri intelligence. Now you can type longer, more descriptive sentences. Reminders will automatically� One of the biggest new features of iOS 14 is Home Screen widgets, which provide information from apps at a glance. The widgets can be pinned to the Home Screen in various spots and sizes, allowing

well, you are using a navigation controller, for "present" a new view controller, you need to push it, for example.

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("IDOFYOURVIEW") as CLASS_NAME_OFYOUR_VIEWCONTROLLER
navigationController?.pushViewController(vc, animated: true)

with the last code you can "present" (push) a new view controller

Now, if you want to make a other action when your press backbutton, try with this lines

override func viewDidLoad {
    super.viewDidLoad()
    self.navigationItem.hidesBackButton = true
    let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Bordered, target: self, action: "back:")
    self.navigationItem.leftBarButtonItem = newBackButton
}

func back(sender: UIBarButtonItem) {
    //in this part you can move to other view controller, examples
    // Go back specific view in your navigation controller
    for controller in self.navigationController!.viewControllers as Array {
    if controller.isKind(of: NAMECLASS_OFYOUR_VIEWCONTROLLER.self) {
        _ =  self.navigationController!.popToViewController(controller, animated: true)
        break
       }
    }
    // Perform your custom actions
    // ...
    // Go back to the previous ViewController
    self.navigationController?.popViewControllerAnimated(true)
}

Regards

8 Third-Party Home Screen Widgets That You Can Try Out Now on , Users interested in trying out these widgets can download Apple's free TestFlight app, tap on the TestFlight links above using an iPhone or iPad,� iOS 14 is slated to drop sometime in Fall 2020 to the public. It will be a free download for iPhones and iPod touch devices. If you have a developer account, you can get the iOS 14 developer beta today via the developer portal .

View Controller class:

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(_ animated: Bool) {
        self.performSegue(withIdentifier: "notLoggedView", sender: self);
    }
}

Class id set to "test":

"Pushing" :

...
let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "test") as ViewController
            navigationController?.pushViewController(vc, animated: true)
...

And sadly error:

'UIViewController' is not convertible to 'ViewController'

Where i made mistake?

iOS 14: Everything We Know, When iOS 14 is released, the Find My app will include support for third-party products and accessories, so item trackers like Tile can be located� iOS 14 and iPadOS 14 public beta: How to download and install them now. Now anyone can try out Apple's latest iPhone and iPad software. Here's how to get it, so you can start using the new App

20 iPhone and iPad tips to become a pro: Everything to know about , If you're not sure if your device will run iOS or iPadOS 13, scroll to the bottom for a You can update directly to the latest available version. On your Android device, select the content that you want to transfer and tap Next. Then — even if your Android indicates that the process is complete — leave both devices alone until the loading bar that appears on your iOS device finishes. The whole transfer can take a while, depending on how much content you're moving.

Switch, Switching from iOS to Android is easy, and you can move all your contacts, calendar events, photos and videos in a few quick steps. Here's how to get started. In iOS 13, widgets showed up in the Today View page to the left of the home screen. But now you can pin widgets directly on your home screen . You simply long press on the screen, tap the plus

iOS 14: Release date, New features, compatible devices, etc , iOS 14 will be released in the fall of 2020. Apple says that iOS 14 can run on the Duration: 1:35:54 Posted: 1 day ago An update to Twitter’s iOS app on Wednesday said the app would now let all users to limit who can reply to their tweets, but it turns out the company may have jumped the gun.

Comments
  • you need to add action to your ok button
  • @AndresGomes if i add it, i have issue with back button and i shouldn't be able to get into sign up page if i logged, but if i press back im redirected to sign up page
  • nop, when you press your ok button, the app will navigate to loginviewcontroller, its easy, check how your push a view controller with navigation controller, when the app is in loginviewcontroller, you need to configure the back button, if not, the app come back to registerviewcontroller
  • @AndreasGomes - self.performSegue(withIdentifier: "test", sender: self); - i add this to ok button and after press i am on valid page, but i have back button and if i press it im again on sign up page - how to avoid this?
  • @iSheep - Don't use performSegue in 'ok' button action. It will add more views to the navigation controller. Pop to your necessary view controller(main view) from the current view and dismiss the alert within the alert action.
  • Im learning swift - not sure what i need to put under <Your_Main_View>. I tried ViewControll and test(i named line to that controler test but it doesn't work
  • I made it with your first idea how to do it, anyway it good to know how to navigate, can you tell me what i should write under <Your_Main_View> ?