Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

295
Vistas
SignUp Button Not Working While Handling RootViewController?

I'm building an iOS app using a Storyboard. The root view controller is a Home View Controller. I'm creating the login/logout process, and it's mostly working fine, but I've got a few issues. I need to know the BEST way to set all this up. When I tap on login and logout the app works fine but when I tap on Sign up Nothing works I have created a navigation controller too. I'm just not sure what the best method is at this point.

I'm Giving you My Details

This Is MY Switcher Class For Managing View

import UIKit

class Switcher {

static func updateRootViewController() {

    let status = UserDefaults.standard.bool(forKey: Constants.kUserDefaults.isSignIn)
    var rootViewController : UIViewController?

    #if DEBUG
    print(status)
    #endif

    if (status == true) {
        let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
        let mainTabBarController = mainStoryBoard.instantiateViewController(withIdentifier: Constants.StoryboardID.homeViewController) as! HomeViewController
        rootViewController = mainTabBarController
    }  else {
    
        let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
        let signInViewController = mainStoryBoard.instantiateViewController(withIdentifier: Constants.StoryboardID.signInViewController) as! SignInViewController
        rootViewController = signInViewController
    }

    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.window?.rootViewController = rootViewController

   }

   }

My App Delegate

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    IQKeyboardManager.shared.enable = true
    Switcher.updateRootViewController()
    return true
}

Sign UP Button

@IBAction func signUpBtnTapped(_ sender: UIButton) {
    let storyBoard = UIStoryboard(name: "Main", bundle: nil)
    guard let signUpVC = storyBoard.instantiateViewController(withIdentifier: "RegistrationViewController") as? RegistrationViewController else {
        return
    }
    print("Register Tapped")
    self.navigationController?.pushViewController(signUpVC, animated: true)
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The issue is the your rootViewController does not have a UINavigationViewController set up, for neither of the Viewcontrollers. what you need to do is instead of instantiating like this:

    if (status == true) {
        let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
        let mainTabBarController = mainStoryBoard.instantiateViewController(withIdentifier: Constants.StoryboardID.homeViewController) as! HomeViewController
        rootViewController = mainTabBarController
    }  else {

        let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
        let signInViewController = mainStoryBoard.instantiateViewController(withIdentifier: Constants.StoryboardID.signInViewController) as! SignInViewController
        rootViewController = signInViewController
}

You need to instantiate a UINavigationController which it's root is these like the following

        if (status == true) {
        let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
        let mainTabBarController = mainStoryBoard.instantiateViewController(withIdentifier: Constants.StoryboardID.homeViewController) as! HomeViewController
        let navigationController = UINavigationController(rootViewController: mainTabBarController)
        rootViewController = navigationController
    }  else {

        let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
        let signInViewController = mainStoryBoard.instantiateViewController(withIdentifier: Constants.StoryboardID.signInViewController) as! SignInViewController
        let navigationController = UINavigationController(rootViewController: signInViewController)

        rootViewController = navigationController
    }

Now your self.navigationController?.pushViewController(signUpVC, animated: true) will work since the "navigationController" exists.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda