'无法在捆绑NSBundle中找到名为'MainTabController'的故事板

时间:2017-09-29 20:04:03

标签: swift xcode storyboard nsbundle

我收到的错误似乎无法修复

  

由于未捕获的异常而终止应用   'NSInvalidArgumentException',原因:'无法找到故事板   在捆绑NSBundle中命名为'MainTabController'   

应用程序将构建并显示登录屏幕,但在出现上述错误后立即崩溃。

我已尝试过与此类似的所有以下内容,并且没有运气。

  1. 删除info.plist文件中对storyboard的引用。当我这样做时,应用程序确实启动但我得到一个黑屏,因为它没有加载故事板。
  2. 摆弄Target Membership Main.storyboard。
  3. 从项目中删除故事板,清理,运行,然后重新添加故事板。
  4. 卸载Xcode,重新安装Xcode。
  5. 删除派生数据文件夹。
  6. 问题似乎与我的 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)
        }
    

    如果我注释掉mainTabController行,应用程序将完美运行,如果我取消注释loggedInVC行并且注释掉mainTabController行,它也可以完美地工作。

    非常感谢任何建议。

    下面是我的整个 ViewController.swift 代码和我工作区的屏幕截图

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

3 个答案:

答案 0 :(得分:4)

故事板的名称是什么?是MainTabController.storyboard还是Main.storyboard

您正在尝试加载名为" MainTabController"的故事板:

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

但之前你称之为Main.storyboard:

  

摆弄目标会员Main.storyboard。

此外,如果主标签控制器与登录视图控制器位于同一个故事板中,那么您可以尝试使用它:

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

答案 1 :(得分:1)

您的故事板名为Main.storyboardMainTabControllerMain故事板中的控制器。

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

答案 2 :(得分:0)

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

您的故事板名为“Main”