'在 NSBundle 包中找不到名为 'MainTabController' 的故事板
'Could not find a storyboard named 'MainTabController' in bundle NSBundle
我收到的似乎无法修复的错误是
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'Could not find a storyboard
named 'MainTabController' in bundle NSBundle
应用程序将构建并显示登录屏幕,但会立即崩溃并出现上述错误。
我已经尝试了其他 post 与此类似的所有以下方法,但没有成功。
- 正在删除对 info.plist 文件中故事板的引用。当我执行此操作时,应用程序确实启动了,但由于它没有加载情节提要,我出现了黑屏。
- Fiddle 与目标会员 Main.storyboard.
- 从项目中删除故事板,清理,运行,然后再次添加故事板。
- 卸载 Xcode,重新安装 Xcode。
- 正在删除派生数据文件夹。
问题似乎出在我的 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)
}
}
let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)
您的故事板名为 "Main"
您的故事板被命名为 Main.storyboard
。 MainTabController
是 Main
故事板中的控制器。
let mainstoryboard = UIStoryboard(name: "Main", bundle: nil)
let mainTabController = mainstoryboard.instantiateViewController(withIdentifier: "MainTabController") as! MainTabController
mainTabController.selectedViewController = mainTabController.viewControllers?[1]
你的故事板叫什么名字?是 MainTabController.storyboard
还是 Main.storyboard
?
您正在尝试加载名为“MainTabController
”的故事板:
let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)
但之前你称它为Main.storyboard:
Fiddle with the Target Membership Main.storyboard.
此外,如果主选项卡控制器与您的登录视图控制器在同一个故事板中,那么您可以尝试使用这个:
let mainTabController = self.storyboard.instantiateViewController(withIdentifier: "MainTabController")
我收到的似乎无法修复的错误是
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'MainTabController' in bundle NSBundle
应用程序将构建并显示登录屏幕,但会立即崩溃并出现上述错误。
我已经尝试了其他 post 与此类似的所有以下方法,但没有成功。
- 正在删除对 info.plist 文件中故事板的引用。当我执行此操作时,应用程序确实启动了,但由于它没有加载情节提要,我出现了黑屏。
- Fiddle 与目标会员 Main.storyboard.
- 从项目中删除故事板,清理,运行,然后再次添加故事板。
- 卸载 Xcode,重新安装 Xcode。
- 正在删除派生数据文件夹。
问题似乎出在我的 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)
}
}
let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)
您的故事板名为 "Main"
您的故事板被命名为 Main.storyboard
。 MainTabController
是 Main
故事板中的控制器。
let mainstoryboard = UIStoryboard(name: "Main", bundle: nil)
let mainTabController = mainstoryboard.instantiateViewController(withIdentifier: "MainTabController") as! MainTabController
mainTabController.selectedViewController = mainTabController.viewControllers?[1]
你的故事板叫什么名字?是 MainTabController.storyboard
还是 Main.storyboard
?
您正在尝试加载名为“MainTabController
”的故事板:
let mainstoryboard = UIStoryboard(name: "MainTabController", bundle: nil)
但之前你称它为Main.storyboard:
Fiddle with the Target Membership Main.storyboard.
此外,如果主选项卡控制器与您的登录视图控制器在同一个故事板中,那么您可以尝试使用这个:
let mainTabController = self.storyboard.instantiateViewController(withIdentifier: "MainTabController")