Can't push a view controller again after popping it

887 Views Asked by At

I want to push a view controller onto the screen when a button is pressed. It works fine the first time, but when I go back and press the same button once again, it does not push the view controller again. The same problem persists when I present the view controller in fullscreen mode. But I don't face this problem when presenting the view controller in the default mode, I am able to present and dismiss the view controller as many times as I want. Someone please help me out with my problem.

enter image description here

enter image description here

[![enter image description here][3]][3]

[![enter image description here][4]][4]

[![enter image description here][5]][5]

import UIKit

@main class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    
    let window = UIWindow(frame: UIScreen.main.bounds)
    window.rootViewController = UINavigationController(rootViewController: LoginViewController())
    window.makeKeyAndVisible()
    self.window = window
    
    return true
}

}

@objc func signUpButtonPressed() {
    
    let vc = SignUpViewController()
    self.navigationController?.pushViewController(vc, animated: true)
    
}
@objc func loginButtonPressed() {
    
    self.navigationController?.popViewController(animated: true)
    
}

func configureNavigationBar() {
    
    navigationController?.navigationBar.backgroundColor = .systemBackground
    navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(createButtonPressed))
    title = "Sign Up"
    navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.font: UIFont(name: Extensions.standardFont, size: 25)!]
    
    navigationItem.rightBarButtonItem?.tintColor = .systemBlue
    
}

Please ignore the scrollview in the Sign up window, it is a work in progress and does nothing at this point in time. The Login, done and create account buttons all do the same work which is to pop the signup view controller. I am able to push the signup view controller once and pop it. But if I try to press the sign up button again, the button wouldn't even respond.

1

There are 1 best solutions below

9
Taimoor Arif On

Try this in you objc func to navigate to next view controller:


   @objc func signUpButtonPressedTapped() {

     let storyboard = UIStoryboard(name: "Main", bundle: nil)
     let vc = storyboard.instantiateViewController(withIdentifier: "SignUpViewController") as! SignUpViewController
        
     self.navigationController?.pushViewController(vc, animated: true)
    }
}