'在捆绑 NSBundle 中找不到名为'MainTabController'的故事板 [英] 'Could not find a storyboard named 'MainTabController' in bundle NSBundle
问题描述
我收到的似乎无法修复的错误是
the error I'm receiving that I can't seem to fix is
由于未捕获的异常而终止应用'NSInvalidArgumentException',原因:'找不到故事板在捆绑 NSBundle 中命名为MainTabController"
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.
- 删除 info.plist 文件中对故事板的引用.当我执行此操作时,应用程序确实启动了,但由于它没有加载故事板,因此出现黑屏.
- 调整目标成员资格 Main.storyboard.
- 从项目中删除故事板,清理,运行,然后重新添加故事板.
- 卸载 Xcode,重新安装 Xcode.
- 删除派生数据文件夹.
问题似乎出在我的 presentMainScreen() 方法
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)
}
如果我注释掉 mainTabController 行,应用程序将完美运行,同样如果我取消对 loggingInVC 行的注释并注释掉 mainTabController 行,它也可以完美运行.
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.
非常感谢任何建议.
下面是我的整个ViewController.swift代码和我的工作区截图
below is my entire ViewController.swift code and a screenshot of my 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)
}
}
推荐答案
您的故事板的名称是什么?是 MainTabController.storyboard
还是 Main.storyboard
?
What is the name of your storyboard? Is it MainTabController.storyboard
or Main.storyboard
?
您正在尝试加载名为MainTabController
"的故事板:
You are trying to load a storyboard named "MainTabController
":
let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)
但之前你称它为 Main.storyboard:
But previously you called it Main.storyboard:
调整目标成员资格 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")
这篇关于'在捆绑 NSBundle 中找不到名为'MainTabController'的故事板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!