Nicholas Richardson
Nicholas Richardson

Reputation: 55

'Could not find a storyboard named 'MainTabController' in bundle NSBundle

the error I'm receiving that I can't seem to fix is

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'MainTabController' in bundle NSBundle

the app will build and the login screen will display but crashes immediately after with the error stated above.

I have tried all of the following from other post similar to this and have had no luck.

  1. Removing the reference to the storyboard in the info.plist file. When I do this the app does start but I get a black screen as it doesn't load the storyboard.
  2. Fiddle with the Target Membership Main.storyboard.
  3. Remove the storyboard from the project, clean, run and then adding the storyboard back again.
  4. Uninstall Xcode, reinstall Xcode.
  5. Deleting the Derived Data folder.

the problem appears to be with my presentMainScreen() method

func presentMainScreen(){
     let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)
      let mainTabController = mainstoryboard.instantiateViewController(withIdentifier: "MainTabController") as! MainTabController
        mainTabController.selectedViewController = mainTabController.viewControllers?[1]
        //let storyboard:UIStoryboard = UIStoryboard(name:"Main", bundle:nil)
        //let loggedInVC:LoggedInVC = storyboard.instantiateViewController(withIdentifier: "LoggedInVC") as! LoggedInVC
        //self.present(loggedInVC, animated: true, completion: nil)
    }

if I comment out the mainTabController lines the app will work perfectly, also if I uncomment the loggedInVC lines and with the mainTabController lines commented out it works perfectly as well.

any suggestions are greatly appreciated.

below is my entire ViewController.swift code and a screenshot of my workspace

workspace

ViewController.swift

import UIKit
import FirebaseAuth

class ViewController: UIViewController {

    @IBOutlet weak var emailTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!

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

    override func viewDidAppear(_ animated: Bool) {


        if Auth.auth().currentUser != nil {
            print("success")

          self.presentMainScreen()
        }
    }

    @IBAction func creatAccountTapped(_ sender: Any) {



        if let email = emailTextField.text, let password = passwordTextField.text {

            Auth.auth().createUser(withEmail: email, password: password, completion:{ user, error in
                if let firebaseError = error {
                print(firebaseError.localizedDescription)
                return
                }
                print("success")
               self.presentMainScreen()

        })

    }
}

@IBAction func loginButtonTapped(_ sender: Any) {



if let email = emailTextField.text, let password = passwordTextField.text {

    Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
        if let firebaseError = error {
            print(firebaseError.localizedDescription)
            return
         }

       print("success")

      self.presentMainScreen()

    })

    }

  }

    func presentMainScreen(){
     let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)
      let mainTabController = mainstoryboard.instantiateViewController(withIdentifier: "MainTabController") as! MainTabController
        mainTabController.selectedViewController = mainTabController.viewControllers?[1]



       //let storyboard:UIStoryboard = UIStoryboard(name:"Main", bundle:nil)
        //let loggedInVC:LoggedInVC = storyboard.instantiateViewController(withIdentifier: "LoggedInVC") as! LoggedInVC
        //self.present(loggedInVC, animated: true, completion: nil)
    }
}

Upvotes: 3

Views: 6787

Answers (3)

Istvan
Istvan

Reputation: 216

What is the name of your storyboard? Is it MainTabController.storyboard or Main.storyboard?

You are trying to load a storyboard named "MainTabController":

let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)

But previously you called it Main.storyboard:

Fiddle with the Target Membership Main.storyboard.

Also if the main tab controller is in the same storyboard as your login view controller then you can try to use this:

let mainTabController = self.storyboard.instantiateViewController(withIdentifier: "MainTabController")

Upvotes: 4

Vini App
Vini App

Reputation: 7485

Your story board is named as Main.storyboard. MainTabController is the controller in the Main storyboard.

let mainstoryboard = UIStoryboard(name: "Main", bundle: nil)
let mainTabController = mainstoryboard.instantiateViewController(withIdentifier: "MainTabController") as! MainTabController
mainTabController.selectedViewController = mainTabController.viewControllers?[1]

Upvotes: 1

Lou Franco
Lou Franco

Reputation: 89232

let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)

Your storyboard is named "Main"

Upvotes: 0

Related Questions