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

一笑奈何 提交于 2019-12-07 16:26:53

问题


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)
    }
}

回答1:


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")



回答2:


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]



回答3:


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

Your storyboard is named "Main"



来源:https://stackoverflow.com/questions/46496188/could-not-find-a-storyboard-named-maintabcontroller-in-bundle-nsbundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!